Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shared session vs. session with default configuration

Tags:

objective-c

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];
like image 739
Ethan Avatar asked Aug 14 '14 02:08

Ethan


2 Answers

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.

like image 170
Rob Avatar answered Nov 15 '22 18:11

Rob


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.

like image 1
Buntylm Avatar answered Nov 15 '22 17:11

Buntylm