Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

App is crashing when loading multiple images from server using AFNetworking

I have integrated the AFNetworking library in my app to download images from a URL and the app is crashing when we are loading multiple images.

When I analyse my code using the Xcode crash report list (Xcode -> Window -> Organizer -> Crashes -> Our app), it is showing 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 anyone help me sort out this problem?

like image 516
Brjv Avatar asked Nov 30 '15 15:11

Brjv


1 Answers

Try 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];
like image 91
Ashutosh Maurya Avatar answered Sep 21 '22 18:09

Ashutosh Maurya