AFNetworking 2.0 - 如何下载uiimage异步 [英] AFNetworking 2.0 - How to download uiimage async

查看:111
本文介绍了AFNetworking 2.0 - 如何下载uiimage异步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

谢谢

推荐答案

你可以做到

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

还提到如何使用AFNetworking 2.0下载图像?

这篇关于AFNetworking 2.0 - 如何下载uiimage异步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆