<tfoot id='Tg2kH'></tfoot>
    • <bdo id='Tg2kH'></bdo><ul id='Tg2kH'></ul>

      <i id='Tg2kH'><tr id='Tg2kH'><dt id='Tg2kH'><q id='Tg2kH'><span id='Tg2kH'><b id='Tg2kH'><form id='Tg2kH'><ins id='Tg2kH'></ins><ul id='Tg2kH'></ul><sub id='Tg2kH'></sub></form><legend id='Tg2kH'></legend><bdo id='Tg2kH'><pre id='Tg2kH'><center id='Tg2kH'></center></pre></bdo></b><th id='Tg2kH'></th></span></q></dt></tr></i><div id='Tg2kH'><tfoot id='Tg2kH'></tfoot><dl id='Tg2kH'><fieldset id='Tg2kH'></fieldset></dl></div>

        <legend id='Tg2kH'><style id='Tg2kH'><dir id='Tg2kH'><q id='Tg2kH'></q></dir></style></legend>

        <small id='Tg2kH'></small><noframes id='Tg2kH'>

        在运行 AFHTTPSessionManager 的 AFNetworking 2 中设置并发任务限制

        时间:2023-10-05
        <tfoot id='NZpIg'></tfoot>
            <tbody id='NZpIg'></tbody>

            <legend id='NZpIg'><style id='NZpIg'><dir id='NZpIg'><q id='NZpIg'></q></dir></style></legend>
            <i id='NZpIg'><tr id='NZpIg'><dt id='NZpIg'><q id='NZpIg'><span id='NZpIg'><b id='NZpIg'><form id='NZpIg'><ins id='NZpIg'></ins><ul id='NZpIg'></ul><sub id='NZpIg'></sub></form><legend id='NZpIg'></legend><bdo id='NZpIg'><pre id='NZpIg'><center id='NZpIg'></center></pre></bdo></b><th id='NZpIg'></th></span></q></dt></tr></i><div id='NZpIg'><tfoot id='NZpIg'></tfoot><dl id='NZpIg'><fieldset id='NZpIg'></fieldset></dl></div>
              <bdo id='NZpIg'></bdo><ul id='NZpIg'></ul>

              • <small id='NZpIg'></small><noframes id='NZpIg'>

                  本文介绍了在运行 AFHTTPSessionManager 的 AFNetworking 2 中设置并发任务限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  所以我知道在旧的 AFNetworking 中使用 AFHTTPClient 是可能的,而且我知道如果我使用 AFHTTPRequestOperationManager 我可以设置队列的限制,但是我不能让 AFHTTPSessionManager 一次只运行 x 个请求而不使用成功块(我不想)自己实现它.

                  so I know that in the old AFNetworking this was possible using the AFHTTPClient, and I know that if I use AFHTTPRequestOperationManager I can set the queue's limit, but I can't make AFHTTPSessionManager to run only x requests at a time without implementing it by myself using the success block (which I don't want to).

                  以下代码并未限制我的连接:

                  The following code did NOT limit my connections:

                  AFHTTPSessionManager *manager = [AFHTTPSessionManager 管理器];manager.operationQueue.maxConcurrentOperationCount = 1;

                  AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; manager.operationQueue.maxConcurrentOperationCount = 1;

                  根据这里的一个有趣的讨论,我对我的服务器有很多请求,我把它阻塞了直到我超时,所以我真的需要限制我的并发连接数.

                  In line with an interesting discussion here, I have a lot of requests to my server and I choke it until I get timeouts, so I really need to limit my concurrent connections.

                  我错过了什么?

                  推荐答案

                  AFHTTPSessionManager 使用任务而不是操作(特别是 NSURLSessionDataTask),这就是为什么你不能设置操作队列.

                  AFHTTPSessionManager uses tasks instead of operations (NSURLSessionDataTask, specifically), which is why you can't set an operation queue.

                  正如你在这个类的实现中看到的,任务会立即启动([task resume])并且不会添加到任何类型的队列中.

                  As you can see in the implementation of this class, tasks are immediately started ([task resume]) and not added to any sort of queue.

                  因此,不幸的是,没有内置的 AFNetworking 方法可以使用 AFHTTPSessionManager 设置并发任务的数量限制.

                  Consequently, and unfortunately, there is no built-into-AFNetworking way to set a limit to the number of concurrent tasks using AFHTTPSessionManager.

                  可能的替代方案:

                  1. 使用 AFHTTPRequestOperationManager 代替(这就是我正在做的)
                  2. 构建一个以任务为属性的NSOperation子类,并在您的子类的[operation start]方法中启动该任务
                  3. 创建一个 Grand Central 串行队列并在此队列中创建和启动任务
                  4. 如果你的请求都发往同一个主机,直接访问基础 URL 加载系统中的 HTTPMaximumConnectionsPerHost 选项,如下所示:

                  1. Use AFHTTPRequestOperationManager instead (this is what I'm doing)
                  2. Build an NSOperation subclass that has a task as a property, and start the task in the [operation start] method of your subclass
                  3. Create a Grand Central serial queue and create and start tasks in this queue
                  4. If your requests are all to the same host, directly access the HTTPMaximumConnectionsPerHost option in the foundation URL loading system, like so:

                  [NSURLSessionConfiguration defaultSessionConfiguration].HTTPMaximumConnectionsPerHost = 4;
                  

                  这种方法有许多注意事项,在 Apple 文档.

                  This approach has a number of caveats, which are discussed in the Apple documentation.

                  如果您最终完成了 #2,请将其作为拉取请求提交给 AFNetworking - 这将是一个受欢迎的补充.

                  If you wind up doing #2, please submit it as a pull request to AFNetworking - it would be a welcome addition.

                  这篇关于在运行 AFHTTPSessionManager 的 AFNetworking 2 中设置并发任务限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何制作多人游戏 下一篇:如何在 iOS 4 中列出 TCP/UDP 连接

                  相关文章

                    <tfoot id='uytxm'></tfoot>
                    <i id='uytxm'><tr id='uytxm'><dt id='uytxm'><q id='uytxm'><span id='uytxm'><b id='uytxm'><form id='uytxm'><ins id='uytxm'></ins><ul id='uytxm'></ul><sub id='uytxm'></sub></form><legend id='uytxm'></legend><bdo id='uytxm'><pre id='uytxm'><center id='uytxm'></center></pre></bdo></b><th id='uytxm'></th></span></q></dt></tr></i><div id='uytxm'><tfoot id='uytxm'></tfoot><dl id='uytxm'><fieldset id='uytxm'></fieldset></dl></div>

                    <legend id='uytxm'><style id='uytxm'><dir id='uytxm'><q id='uytxm'></q></dir></style></legend>

                    <small id='uytxm'></small><noframes id='uytxm'>

                      • <bdo id='uytxm'></bdo><ul id='uytxm'></ul>