sendAsynchronousRequest deprecated?

I was somewhat surprised today, when looking up NSURLConnection in the documentation, to find that sendAsynchronousRequest and most of its other methods have been deprecated.


I read through the documentation page but didn't see any mention of why these methods are deprecated or what Apple exepcts us to use instead.


I'm hoping this is just some kind of error in the documentation. I've used NSURLConnection for years, it works great, and I can't think of any reason why Apple would want to deprecate it.

Frank

I believe all of NSURLConnection is now deprecated. You are expected to use NSURLSession.


But as you mentioned, there's a lot of code out there still using it, so code using NSURLConnection probably won't break for the foreseeable future. I suppose they could make it "private API" if they wanted to deprecate it with extreme prejudice but that seems unlikely. There was some discussion of it in one of the WWDC 2015 videos.

Thanks for the reply.


I remember hearing about NSURLSession when they added it -- I looked it over -- didn't see any compelling reason to use it over NSURLConnection.


Any idea what motivated them to make this change? Can NSURLSession do something NSURLConnection can't? Is it safer in some way?


Frank

Since outbound links are mostly banned...the 'net says this about that (humorously translated, from Russian, I think):


  1. Loading and sending of the data in a background
  2. Possibility to stop and continue loading
  3. We could use units and delegates simultaneously so, for example, units we used for data acquisition and error handling, and a delegatny method — for passage of authentification
  4. Session had a special configuration container in whom it are possible to lay down all necessary properties for (requests) all taskov in session, and also, for example, heder for all requests in session
  5. It are possible to use private storage for Cooks, a cache and other
  6. We received more rigorous and reticulated code, unlike a dial-up of messy NSURLConnection

Can NSURLSession do something NSURLConnection can't?

NSURLSession can do many things that NSURLConnection can’t. The most important is that it allows you to group specific requests (instances of NSURLConnection in the old API, instances of NSURLSessionTask in the new) into sessions, which then lets you set parameters on those sessions as a group. This is important because it allows library code to do work within your process without interfering with your app’s code, or other library code running within your process. NSURLConnection relies entirely on a bunch of singletons—some visible to you, like the NSURLCache, some not visible to you, like the TLS session cache—and that makes it very hard to write library code safely.

The reason why NSURLConnection was deprecated is that we don’t want to maintain two very similar APIs forever. But, as junkpile said, there’s a lot of code that uses NSURLConnection, so the implementation is not going to be removed any time soon. OTOH, we’re already seeing new platforms, like watchOS, that have NSURLSession but not NSURLConnection.

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
sendAsynchronousRequest deprecated?
 
 
Q