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 c
You can configure AFHTTPSessionManager
NSURLSessionConfiguration
:
NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];
config.HTTPMaximumConnectionsPerHost = 2;
AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] initWithSessionConfiguration:config];
AFHTTPSessionManager
uses tasks instead of operations (NSURLSessionDataTask
, specifically), which is why you can't set an operation queue.
As you can see in the implementation of this class, tasks are immediately started ([task resume]
) and not added to any sort of queue.
Consequently, and unfortunately, there is no built-into-AFNetworking way to set a limit to the number of concurrent tasks using AFHTTPSessionManager
.
Possible alternatives:
AFHTTPRequestOperationManager
instead (this is what I'm doing)NSOperation
subclass that has a task as a property, and start the task in the [operation start]
method of your subclassIf 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;
This approach has a number of caveats, which are discussed in the Apple documentation.
If you wind up doing #2, please submit it as a pull request to AFNetworking - it would be a welcome addition.