I am trying to download an image using AFNetworking 3.0 doing this way:
- (UIImage *) loadImage:(NSString *) link
{
__block UIImage *image = [UIImage imageNamed:@"no_user_profile_pic.png"];
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.responseSerializer = [AFImageResponseSerializer serializer];
[manager GET:[link stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLHostAllowedCharacterSet]]
parameters:nil
progress:nil
success:^(NSURLSessionTask *task, id responseObject) {
image = (UIImage *) responseObject;
} failure:^(NSURLSessionTask *operation, NSError *error) {
NSLog(@"Load Image error - %@", [error description]);
}];
return image;
}
and every time I am getting this error:
*** Assertion failure in -[AFHTTPRequestSerializer requestWithMethod:URLString:parameters:error:], /Users/.../AFNetworking/AFURLRequestSerialization.m:353
I can't figure out what I am doing wrong. What is that error happening?
stringByAddingPercentEncodingWithAllowedCharacters:
will encrypt the URL including thehttp://
, this wil becomehttp%3A%2F%2F
and there for is no longer a valid URL. – Allwein