Domanda

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

Thanks

È stato utile?

Soluzione

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 download image with AFNetworking 2.0?

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top