AFNetworking 2.0 - 如何下载uiimage异步

时间:2013-10-01 19:13:41

标签: ios objective-c afnetworking afnetworking-2

在使用AFNetworking 2.0的ios中,我如何能够轻松地异步下载远程图像并将其缓存以备将来请求相同的URL?我正在寻找一种方便的方法来接收错误回调和成功的回调。

由于

1 个答案:

答案 0 :(得分:19)

你可以做到

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];

还提到了How to download image with AFNetworking 2.0?