[英]AFNetworking 2: Limit max number of concurrent Download Tasks
I'm dealing with an app that implements a download queue created with AFNetworking 2.0 and I will like to know if there is a way to limit the maximum number of download tasks ( NSURLSessionDownloadTask
) running at the same time. 我正在处理一个实现使用AFNetworking 2.0创建的下载队列的应用程序,我想知道是否有办法限制同时运行的最大下载任务数(
NSURLSessionDownloadTask
)。
My final goal is that my download queue manages all the tasks so one is finished, then the next one will start. 我的最终目标是我的下载队列管理所有任务,一个完成,然后下一个将开始。
I know that, for example, NSOperationQueue
has the maxConcurrentOperationCount
property, but I don't know if AFNetworking 2.0 uses NSOperationQueue in a lower level with download tasks. 我知道,例如,
NSOperationQueue
具有maxConcurrentOperationCount
属性,但我不知道AFNetworking 2.0是否在较低级别使用NSOperationQueue进行下载任务。 Also, I know that AFURLSessionManager
has an NSArray
with all the running download tasks, but is just that, an array. 另外,我知道
AFURLSessionManager
有一个带有所有正在运行的下载任务的NSArray
,但就是这个,一个数组。
Thanks 谢谢
AFNetworking has an operation queue, which you can set the number of concurrent operations AFNetworking有一个操作队列,您可以设置并发操作的数量
[[self.requestOperationManager operationQueue] setMaxConcurrentOperationCount:2];
this works fine for downloads and requests 这适用于下载和请求
Note: a good technique that i use, is to have 2 network managers, one for common requests, which has setMaxConcurrentOperationCount of 1 (i need my requests to be performed sequentially) and a downloader, which has setMaxConcurrentOperationCount to 2 注意:我使用的一个好技术是拥有2个网络管理器,一个用于公共请求,其中setMaxConcurrentOperationCount为1(我需要我的请求按顺序执行)和一个下载器,其setMaxConcurrentOperationCount为2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.