美文网首页
使用SDWebImage同步下载

使用SDWebImage同步下载

作者: 和谐共处 | 来源:发表于2019-07-29 15:34 被阅读0次

代码如下

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

相关文章

网友评论

      本文标题:使用SDWebImage同步下载

      本文链接:https://www.haomeiwen.com/subject/fwvbrctx.html