What are the differences between the two session
objects created in these two different ways:
NSURLSession *session = [NSURLSession sharedSession];
and
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration];
As you're using them, they're functionally very similar. But using sharedSession
doesn't give you the ability to customize the NSURLSessionConfiguration
(e.g. tweak the cache, custom headers, etc.) nor use the delegate-based rendition of NSURLSession
. But if you don't need those features, feel free to use sharedSession
as it's easier.
NSURLSessionConfiguration
session with basic set of properties that control various policies on a sessionwide basis. These properties are set on a session at the time of its creation and cannot be changed later. If you need to change these policy properties, create a new session with a modified session configuration.
sharedSession
Returns a shared singleton session object.
Please review Apple Documents first as these are the source of very information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With