代码如下
- (void)syncDownLoadImageWithUrls:(NSArray<NSURL *> *)urls lastImageInfos:(NSArray *)lastImageInfos callBack:(void(^)(NSArray *imageInfos))callback{
NSMutableArray *copyUrls = urls.mutableCopy;
NSURL *url = copyUrls.firstObject;
NSMutableArray *resultImageInfos = [[NSMutableArray alloc] initWithCapacity:0];
if (lastImageInfos.count>0) {
[resultImageInfos addObjectsFromArray:lastImageInfos];
}
[ [SDWebImageManager sharedManager] loadImageWithURL:url options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {
} completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {
//NSLog(@"url==%@",url);
if (image) {
NSDictionary *imageInfo = @{@"url":url,
@"image":image,
};
[resultImageInfos addObject:imageInfo];
}
[copyUrls removeObject:url];
if (copyUrls.count == 0) {
callback(resultImageInfos);
}else{
[self syncDownLoadImageWithUrls:copyUrls lastImageInfos:resultImageInfos callBack:callback];
}
}];
}
网友评论