Returns a shared singleton session object.
- iOS 7.0+
- macOS 10.9+
- tvOS 9.0+
- watchOS 2.0+
For basic requests, the URL session class provides a shared singleton session object that gives you a reasonable default behavior. By using the shared session, you can fetch the contents of a URL to memory with just a few lines of code.
Unlike the other session types, you do not create the shared session; you merely request it by calling
[NSURLSession shared. As a result, you don’t provide a delegate or a configuration object. Therefore, with the shared session:
You cannot obtain data incrementally as it arrives from the server.
You cannot significantly customize the default connection behavior.
Your ability to perform authentication is limited.
You cannot perform background downloads or uploads while your app is not running.
The shared session uses the shared
NSURLCredential objects, uses a shared custom networking protocol list (configured with
unregister), and is based on a default configuration.
When working with a shared session, you should generally avoid customizing the cache, cookie storage, or credential storage (unless you are already doing so with
NSURLConnection), because there’s a very good chance that you’ll eventually outgrow the capabilities of the default session, at which point you’ll have to rewrite all of those customizations in a manner that works with your custom URL sessions.
In other words, if you’re doing anything with caches, cookies, authentication, or custom networking protocols, you should probably be using a default session instead of the shared session.