AFNetworking 2.0 - How to download uiimage async

On ios using AFNetworking 2.0, how can I easily load a remote image asynchronously and cache it for a future request for the same url? I'm looking for a convenient way to get both error callbacks and successful ones.

thank

+2


source to share


1 answer


You can do

AFHTTPRequestOperation *requestOperation = [[AFHTTPRequestOperation alloc] initWithRequest:urlRequest];
requestOperation.responseSerializer = [AFImageResponseSerializer serializer];
[requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"Response: %@", responseObject);
    _imageView.image = responseObject;

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Image error: %@", error);
}];
[requestOperation start];

      



also mentioned How to upload an image using AFNetworking 2.0?

+19


source







All Articles