Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AFNetworking+UIImageView placeholder image shows up, but not URL image

I'm trying to use the AFNetworking UIImageView call to load images from a URL as shown below:

[self.image setImageWithURL:[NSURL URLWithString:feed.imageURL] placeholderImage:     [UIImage imageNamed:@"logo"]];

The placeholder image always shows up, but the actual image from "feed.imageURL" never does. I've verified that the URL is actually correct. I even hardcoded it to make sure, and still nothing.

My basic app setup is a tab controller...and in viewDidLoad, I call a method "fetchFeed" which performs the HTTP request to gather my JSON data.

My request block looks like:

AFJSONRequestOperation *operation = [AFJSONRequestOperation
                                    JSONRequestOperationWithRequest:request
                                     success:^(NSURLRequest *request, NSHTTPURLResponse   *response, id JSON) {
                                         [self parseDictionary:JSON];
                                         isLoading = NO;
                                         [self.tableView reloadData];

                                         } failure:^(NSURLRequest *request,   NSHTTPURLResponse *response, NSError *error, id JSON) {
                                             NSLog(@"Error: %@", error);
                                             [self showNetworkError];
                                             isLoading = NO;
                                             [self.tableView reloadData];
                                         }];
operation.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/html", nil];
[queue addOperation:operation];
like image 728
Adam Johnson Avatar asked Feb 27 '12 03:02

Adam Johnson


1 Answers

Turns out the server I was requesting the image from was sending content-type "image/jpg" and by default AFNetworking does not support this file type.

I changed the class method in AFImageRequestOperation to look like:

+ (NSSet *)defaultAcceptableContentTypes {
return [NSSet setWithObjects:@"image/tiff", @"image/jpeg", @"image/gif", @"image/png", @"image/ico", @"image/x-icon" @"image/bmp", @"image/x-bmp", @"image/x-xbitmap", @"image/x-win-bitmap", @"image/jpg", nil];
}

and it fixed my problem.

like image 123
Adam Johnson Avatar answered Oct 26 '22 13:10

Adam Johnson