Clicky

iOS Dev Nugget 159 3 Types of NSURLSessionConfiguration

.

Need to run a code review on your codebase? Hire me

In #144 NSURLSession instead of NSURLConnection, I mentioned that we should use the NSURLSession family of classes as a replacement for NSURLConnection and used the default NSURLSessionConfiguration object in the code examples.

There are actually 3 types of NSURLSessionConfigurations available. The default, ephemeral and background sessions, created by +defaultSessionConfiguration, +ephemeralSessionConfiguration and +backgroundSessionConfigurationWithIdentifier: respectively.

The default configuration uses a shared cookie store so it is generally good for web browsing. The ephemeral session configuration uses a store that is only in-memory so it is useful for where privacy is desired. The background session is slightly different because operations using it runs in the background, and will continue running until it is completed or if the app is manually killed by the user in the task switcher.

There are two special properties that only apply to background session configurations. Setting the discretionary property hands control over when the upload/download operations should start to the system. Setting the sessionSendsLaunchEvents property resumes/launches the app in background when transfers are completed.


Your feedback is valuable: Do you want more nuggets like this?   Yes   or   No

.

Like this and want such iOS dev nuggets to be emailed to you, weekly?

Sign Me Up! or follow @iosdevnuggets on Twitter

.

View archives of past issues