Since the AFNetworking 2.0
the AFHTTPClient
has been vanished in the favour of two managers: AFHTTPRequestOperationManager
and AFHTTPSessionManager
. The migration guide says pretty much nothing about the cases when each of them is preferable to use. As far as I can see the basic interaction with a RESTful JSON API
can be implemented using each of them separately.
What are the most suitable cases to use either RequestOperationManager
or SessionManager
?
They are basically equivalent, except that the AFHTTPSessionManager
uses internally the iOS 7/OS X 10.9 NSURLSession
, so it can't be used in iOS 6. AFHTTPRequestOperationManager
is there until NSURLRequest
gets deprecated.
Check here for more info:
So to recap: in order to support the new NSURLSession APIs as well as the old-but-not-deprecated-and-still-useful NSURLConnection, the core components of AFNetworking 2.0 are split between request operation and session tasks. AFHTTPRequestOperationManager and AFHTTPSessionManager provide similar functionality, with nearly interchangeable interfaces that can be swapped out rather easily, should the need arise (such as porting between iOS 6 and 7).
Note that are a few differences between both. AFHTTPSessionManager returns NSURLSessionDataTask objects, which are not NSOperations. That means it's harder to enqueue them and establish dependencies between requests.
also see the subclassing notes for AFHTTPRequestOperationManager
Developers targeting iOS 7 or Mac OS X 10.9 or later that deal extensively with a web service are encouraged to subclass AFHTTPSessionManager, providing a class method that returns a shared singleton object on which authentication and other configuration can be shared across the application.
For developers targeting iOS 6 or Mac OS X 10.8 or earlier, AFHTTPRequestOperationManager may be used to similar effect.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With