我想要缓存图像而不在任何 imageView 中显示它们我想如何在我稍后更改为使用 by url 时取得进展
I want cache images without show them in any imageView how do this i want do progress while I´m change to use the by url later
SDWebImageDownloader *downloader = [SDWebImageDownloader sharedDownloader];
[downloader downloadImageWithURL:[[NSURL alloc] initWithString:url]
options:0
progress:^(NSInteger receivedSize, NSInteger expectedSize) {
// progression tracking code
}
completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
if (image && finished) {
}});
如果您想使用 SDWebImage,那么只需使用 url 下载数据,不要将其分配给 imageView,您使用的库将通过这样做来缓存它。
试试这个:
-(UIImage *)downloadImageAsync:(NSString *)imageKey
{
NSLog(@"image key : %@",imageKey);
__block UIImage *returnedImage;
SDWebImageManager *manager = [SDWebImageManager sharedManager];
[manager downloadWithURL:[NSURL URLWithString:imageKey] options:0 progress:^(NSUInteger receivedSize, long long expectedSize){
NSLog(@"received size %d expected size %lld", receivedSize, expectedSize);
}completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType,BOOL finished){
if(image && finished) {
returnedImage = image;
}
}];
if(returnedImage == nil) {
NSLog(@"Returned Image Nil");
}
return returnedImage;
}
SDWebImageDownloader *downloader = [SDWebImageDownloader sharedDownloader];
[downloader downloadImageWithURL:[[NSURL alloc] initWithString:url]
options:0
progress:^(NSInteger receivedSize, NSInteger expectedSize) {
// progression tracking code
}
completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
if (image && finished) {
}});
如果您想使用 SDWebImage,那么只需使用 url 下载数据,不要将其分配给 imageView,您使用的库将通过这样做来缓存它。
试试这个:
-(UIImage *)downloadImageAsync:(NSString *)imageKey
{
NSLog(@"image key : %@",imageKey);
__block UIImage *returnedImage;
SDWebImageManager *manager = [SDWebImageManager sharedManager];
[manager downloadWithURL:[NSURL URLWithString:imageKey] options:0 progress:^(NSUInteger receivedSize, long long expectedSize){
NSLog(@"received size %d expected size %lld", receivedSize, expectedSize);
}completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType,BOOL finished){
if(image && finished) {
returnedImage = image;
}
}];
if(returnedImage == nil) {
NSLog(@"Returned Image Nil");
}
return returnedImage;
}