Recommendation when choosing between AFHTTPRequestOperationManager and AFHTTPSessionManager
Asked Answered
T

2

15

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?

Tovatovar answered 11/10, 2013 at 8:36 Comment(0)
I
18

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.

Interlinear answered 14/10, 2013 at 13:7 Comment(1)
Can you please elaborate this part a bit "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." ?Deposition
B
1

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.

Brehm answered 31/10, 2013 at 19:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.