I want to set tableview cell images in one of my apps. I use AFNetworking (1.2.1)
and I do it with setImageWithURLRequest
.
My code in which I set images looks like this:
if (user.avatar) {
NSString *imageUrl = user.avatar.url;
[cell.profileImage setImageWithURLRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:imageUrl]] placeholderImage:nil success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
[cell setNeedsLayout];
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
NSLog(@"Error: %@", error);
}];
}
My error log returns this:
Error: Error Domain=NSURLErrorDomain Code=-999 "The operation couldn’t be completed. (NSURLErrorDomain error -999.)" UserInfo=0x1f5b56a0 {NSErrorFailingURLKey=https://d2rfichhc2fb9n.cloudfront.net/image/5/Cf7T_BA6- NFGL5ah0w4hdvmk_Vp7InMiOiJzMyIsImIiOiJhZG4tdXNlci1hc3NldHMiLCJrIjoiYXNzZXRzL3VzZXIvZTIvM2MvMjA vZTIzYzIwMDAwMDAwMDAwMC5qcGciLCJvIjoiIn0}
And the images dosn't get set. I didn't have this problem before I updated to AFNetworking (1.2.1)
. Any ideas?
Update
Tried to strip the whitespace from the url like this:
NSString *imageUrl = [user.avatar.url stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
But I get the same error. And it could maybe be dangerous if the API sometime would contain a image file name that contains whitespaces.