【发布时间】:2016-03-03 07:34:22
【问题描述】:
我正在尝试将带有进度的图像从网络服务器直接保存到照片应用程序。这是我目前使用的没有进展:
NSURLSessionDownloadTask *dl = [[NSURLSession sharedSession]
downloadTaskWithURL:url completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error) {
if ( !error )
{
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:location]];
completionBlock(YES,image);
} else{
completionBlock(NO,nil);
}
}
];
[dl resume];
我知道我可以使用NSURLSessionDownloadDelegate 来获取下载进度,但我想使用AFNetworking 来下载图像并在下载时获取进度。我知道 AFNetworking 有一种方法可以在 imageview 中显示图像,例如
[postCell.iv_postImage setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",[[Utilities sharedUtilities] basePath],[item.imagePath substringFromIndex:2]]]];
但是有没有类似的方法来下载图片?
【问题讨论】:
-
这只是一个下载,没有特定的图像......
-
只是照片应用的普通 jpeg
-
但是一个问题是,AFNetworking 3.X 需要 xcode 7 并且它仍处于测试阶段。
-
你应该使用github.com/rs/SDWebImage。简单且最适合带进度的图像下载
标签: ios objective-c progress afnetworking-3