简体   繁体   English

AFNetworking 2:限制最大并发下载任务数

[英]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.

相关问题 在运行AFHTTPSessionManager的AFNetworking 2中设置对并发任务的限制 - setting limit on concurrent tasks in AFNetworking 2 running AFHTTPSessionManager AFNetworking:调度并发队列并在其中运行同步任务 - AFNetworking: Dispatching a concurrent queue and running synchronous tasks within that 限制AFURLSessionManager中的并发下载数量 - limit the number of concurrent downloads in AFURLSessionManager AFNetworking中的并发任务 - Concurrent task in AFNetworking 所有后台作业失败,并且达到最大并发作业限制-解析 - All background jobs failing with max concurrent job limit reached - Parse AFNetworking任务死锁(tasksForKeyPath) - AFNetworking deadlock on tasks (tasksForKeyPath) AFNetworking 2和后台任务 - AFNetworking 2 and background tasks 会话完成所有任务后,如何使用AFNetworking 3.0在后台下载大文件并显示本地通知 - How to download large file in background using AFNetworking 3.0 and present local notification when session completes all the tasks AFNetworking/NSURLSession 创建100多个任务下载文件需要很长时间 - AFNetworking/NSURLSession takes long to create more than 100 tasks to download files AFNetworking从URL下载 - AFNetworking download from url
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM