大佬教程收集整理的这篇文章主要介绍了ios – AFNetworking 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 @R_768_10586@lBytesRead,long long @R_768_10586@lBytesExpectedToRead){ }]; 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 @R_768_10586@lnumberOfOperations) { } 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下载完成后的多个图像所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。