ios – AFNetworking 2.0下载完成后的多个图像

ios – AFNetworking 2.0下载完成后的多个图像,第1张

概述我正在试图找出一种使用AFNewtorking 2.0下载多个图像的方法.我在这里看过很多帖子,但找不到我要找的答案,希望你们能帮助我. 问题是我想知道所有下载完成后以及所有下载的图像. 所以我有一个带有图像URL蚂蚁的数组试图做这样的事情. for(NSString *photoUrlString in self.photos){ NSURL *url = [NSURL URL 我正在试图找出一种使用AFNewtorking 2.0下载多个图像的方法.我在这里看过很多帖子,但找不到我要找的答案,希望你们能帮助我.

问题是我想知道所有下载完成后以及所有下载的图像.
所以我有一个带有图像URL蚂蚁的数组试图做这样的事情.

for(Nsstring *photoUrlString in self.photos){        NSURL *url = [NSURL URLWithString:photoUrlString];        AFhttpRequestoperation *requestoperation = [[AFhttpRequestoperation alloc] initWithRequest:[NSURLRequest requestWithURL:url]];        requestoperation.responseSerializer = [AFImageResponseSerializer serializer];        [requestoperation setCompletionBlockWithSuccess:^(AFhttpRequestoperation *operation,ID responSEObject) {        } failure:^(AFhttpRequestoperation *operation,NSError *error) {            NSLog(@"Image error: %@",error);        }];        [requestoperation start];    }

我已经找到了一些答案,将这些请求放入队列并将最大并发 *** 作设置为1.但不知道它是如何工作的.

任何帮助表示赞赏,提前谢谢!

解决方法
for(Photo *photo in array){    //form the path where you want to save your downloaded image to    Nsstring *constPath = [photo imageFullPath];    //url of your photo    NSURL *url = [NSURL URLWithString:photo.serverPath];    AFhttpRequestoperation *op = [[AFhttpRequestoperation alloc] initWithRequest:[NSURLRequest requestWithURL:url]];    op.responseSerializer = [AFImageResponseSerializer serializer];    op.outputStream = [NSOutputStream outputStreamTofileAtPath:constPath append:NO];    op.queuePriority = NSOperationQueuePriorityLow;    [op setDownloadProgressBlock:^(NSUInteger bytesRead,long long totalBytesRead,long long totalBytesExpectedToRead){    }];    op.completionBlock = ^{        //do whatever you want with the downloaded photo,it is stored in the path you create in constPath    };    [requestArray addobject:op];}NSArray *batches = [AFURLConnectionoperation batchOfRequestoperations:requestArray progressBlock:^(NSUInteger numberOfFinishedOperations,NSUInteger totalNumberOfOperations) {} completionBlock:^(NSArray *operations) {    //after all operations are completed this block is called    if (successBlock)        successBlock();}];[[NSOperationQueue mainQueue] addOperations:batches waitUntilFinished:NO];
总结

以上是内存溢出为你收集整理的ios – AFNetworking 2.0下载完成后的多个图像全部内容,希望文章能够帮你解决ios – AFNetworking 2.0下载完成后的多个图像所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1065993.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-26
下一篇2022-05-26

发表评论

登录后才能评论

评论列表(0条)

    保存