
问题是我想知道所有下载完成后以及所有下载的图像.
所以我有一个带有图像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下载完成后的多个图像所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)