Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shared URLSession vs URLSession with default configuration

Tags:

What is the difference between Shared URLSession and URLSession with default configuration?

In my app i was using URLSession.shared to send a request to server. Now i'm trying to change it to URLSession.init(configuration: URLSessionConfiguration.default).

But if i use URLSession.init(configuration: URLSessionConfiguration.default) all my request are taking more time to load.

Compared to URLSession.shared, URLSession.init(configuration: URLSessionConfiguration.default) is taking more time to load the request.(Shared Session is 5 to 10 time faster than URLSession with default Configuration).

What is the Difference between these two methods?

Why URLSession With Default Configuration is taking more to load the request?

like image 593
sAsuKe Avatar asked Sep 17 '19 10:09

sAsuKe


1 Answers

Limitations of the Shared Session

  • You don’t provide a delegate or a configuration object.
  • You can’t obtain data incrementally as it arrives from the server.
  • You can’t significantly customize the default connection behavior.
  • Your ability to perform authentication is limited.
  • You can’t perform background downloads or uploads when your app isn’t running.

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.

For more info: https://developer.apple.com/documentation/foundation/urlsession/1409000-shared

like image 65
Alexander Algashev Avatar answered Sep 22 '22 10:09

Alexander Algashev