Application crashes when loading multiple images from a server using AFNetworking

I have included the AFNetworking library in my application for downloading images from a URL, and the application crashes when we upload multiple images.

When I analyze my code using the Xcode crash report list (Xcode β†’ Window β†’ Organizer β†’ Crashes β†’ Our app), it shows an error in the AFNetworking library for this line of code:

Class : UIImageView+AFNetworking

Method Name : setImageWithURLRequest

Line of code : [[[self class] af_sharedImageRequestOperationQueue] addOperation:self.af_imageRequestOperation];

Can someone help me deal with this issue?

+8
ios afnetworking
source share
3 answers

Try using the following code

  NSURL *url = [NSURL URLWithString:@"YourImageURL"]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; UIImage *placeholderImage = [UIImage imageNamed:@"placeholder"]; __weak UIImageView *weakImageView = yourImageView; [weakImageView setImageWithURLRequest:request placeholderImage:placeholderImage success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) { weakImageView.image = image; } failure:nil]; 
+4
source share

There are many unit tests for loading images and a new architecture in the 3.0.0 branch with additional tests covering loading multiple images.

+1
source share

https://github.com/Alamofire/Alamofire install this pod

Try using the following code to upload multiple images to the server code:

  Alamofire.upload( .POST, urlString, multipartFormData: { multipartFormData in for image in images { if let imageData = UIImageJPEGRepresentation(image, 0.1) { multipartFormData.appendBodyPart(data: imageData, name: "file", fileName: "file.jpeg", mimeType: "image/jpeg") } } }, encodingCompletion: { encodingResult in switch encodingResult { case .Success(let upload, _, _): upload.responseJSON(completionHandler: { (response) -> Void in if response.result.error != nil { print("Something is wrong while uploading images.") } else { } }) case .Failure(let encodingError): print(encodingError) } } ) 
0
source share

All Articles