NSURLSession Tech Talk Video

Check out this tech talk video on NSURLSession – includes a demo project and Q&A! By Ray Wenderlich.

Leave a rating/review
Save for later


Hide contents

In our latest monthly Tech Talk, Charlie Fulton gave a great talk on NSURLSession.

We had a lot of fun, so wanted to post it here so you all could enjoy!

Note that we had some technical difficulties toward the beginning of the hangout, so I have modified the video to start at the point at which the screenshare was finally working OK :]

Source Code

Here is the source code of all of the demos from the tech talk.

Q&A Clarifications

This is the first time we ran the hangout live, and we had a lot of great live Q&A from the audience. Charlie has sent me a few clarifications and additional notes to post regarding some of the questions that came up:

Regarding cache management and file management

“Reading the documentation on Apple’s URL Loading System Guide provides some great detail on how this works.

Also, this diagram gives a great overview. Important: The NSURLSession API involves many different classes working together in a fairly complex way that may not be obvious if you read the reference documentation by itself. Before using this API, you should read the URL Loading System Programming Guide to gain a conceptual understanding of how these classes interact with one another.”

So is it an async request or do I need to use GCD?

“The requests are asynchronous, and by default the completion handlers are running in a background thread. I like to use GCD to update UIKit on the main thread, but you could also use the performSelector… way.”

Are run loops for NSURLSessions handled the same way as NSURLConnection? For example, needing to run a NSURLConnection with a different run loop within NSOperation code blocks.

“They are handled the same way; IE you would need to roll your own solution for this. One tip suggested by Alexis would be to create all of your tasks (they start in a suspended state) and then add them to your own queue, calling resume on them, etc. You can also use the description property on a task to inspect them.”

So is the completion block running on the main thread or the default for the shared queue background queue? I still didn’t get it.

“By default it’s running on a background thread.”

Does NSURLSession bring anything to the table as far as OAuth is concerned?

“Unfortunately No. But I have a solution for OAuth that talks to dropbox’s api that you are welcome to use. It’s included in the sample app in the NSURLSession chapter of iOS7 by Tutorials.”

Want to Join Us Next Month?

Thanks again Charlie for giving a great talk and having the guts to do our first live hangout :] We hope you enjoyed it!

Next month, Pietro Rea will give a talk on the new multitasking APIs in iOS 7, which allow you to download data or files from a remote web service periodically in the background to keep your app up-to-date.

We will be broadcasting this talk live on Jan 7 at 7:00 PM EST, so if you want to join us sign up here! As you watch the talk, you can submit any Q&A you may have live.

Hope to see some of you there! :]