我想知道有没有办法用我的代码一个一个地下载图像?现在异步
NSString *urlString = link;
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
AFHTTPRequestOperation *requestOperation = [[AFHTTPRequestOperation alloc] initWithRequest:urlRequest];
requestOperation.responseSerializer = [AFImageResponseSerializer serializer];
[requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
completion(operation, responseObject, nil);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[RequestAPI sharedInstance].downloadsCount -= 1;
DDLogError(@"FAIL download image: %@",error);
}];
[requestOperation start];
答案 0 :(得分:0)
试试这个解决方案
NSObject
类来下载图像。让我们称之为DownloadImages
。该类有一系列要下载的图像arrayOfImagesURL
。DownloadImages
创建一个委托,以便在下载完图像后进行回调。详细了解详情here。AFNetworking
,您也可以使用iOS 7 API NSURLSession
来实现此目的。因此,在下载任务的完成块中,您需要做两件事:
arrayOfImagesURL
。告诉我是否需要进一步澄清。