Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should we consider transitioning from AFNetworking to NSUrlSession? [closed]

I have been using AFNetworking for a while, however recently heard opinion NSUrlSession provides the same functionality as AFNetworking, so no need to use AFNetworking. Mostly I'm interested in these features like operations, clients and lazy image down-loader, however, not sure how much additional code I will need to write. Has anybody transitioned from AFNetworking to NSUrlSession?

like image 763
Centurion Avatar asked Dec 02 '14 13:12

Centurion


2 Answers

NSURLSession does not reproduce all of the richness of AFNetworking (notably, the construction of complex HTTP requests and the simplified parsing of the responses). So if you're leveraging these features of AFNetworking, then you might want to stay with AFNetworking.

For the programmer who is currently using NSURLConnection, though, NSURLSession offers some nice enhancements. The block-based methods of NSURLSession are richer than what was provided by NSURLConnection. Also, NSURLSession offers background session features that allow requests to continue even if the app isn't running.

For the AFNetworking developer using AFHTTPRequestOperationManager (which is NSURLConnection-based), AFNetworking now offers AFHTTPSessionManager, a very similar interface that leverages NSURLSession internally (but, curiously, not NSOperationQueue-based). So, if you want to enjoy some NSURLSession features with AFNetworking, consider using AFHTTPSessionManager instead of AFHTTPRequestOperationManager.

like image 157
Rob Avatar answered Oct 03 '22 23:10

Rob


AFNetworking is written on top of NSUrlSession hence no reason to go away from it unless you want to handle all of the implementation details which AFNetworking has already taken care of for you and more to the point it is tested by thousands of users on a daily basis hence is a pretty stable and mature library.

like image 26
darren102 Avatar answered Oct 03 '22 23:10

darren102