Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recommendation when choosing between AFHTTPRequestOperationManager and AFHTTPSessionManager

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?

like image 474
Oleksandr Avatar asked Oct 11 '13 08:10

Oleksandr


2 Answers

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.

like image 159
José Manuel Sánchez Avatar answered Nov 07 '22 16:11

José Manuel Sánchez


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.

like image 26
Iggy Avatar answered Nov 07 '22 17:11

Iggy