URLSessionConfiguration

The URLSessionConfiguration class defines the behavior and policies to use when using the URLSession object to connect to a URL. When using the URLSession object, we usually create a URLSessionConfiguration instance first, because an instance of this class is required when we create an instance of the URLSession class.

The URLSessionConfiguration class defines three session types:

  • Default session configuration: This manages the upload and download tasks with default configurations
  • Ephemeral session configuration: This configuration behaves similarly to the default session configuration, except that it does not cache anything to disk
  • Background session configuration: This session allows for uploads and downloads to be performed, even when the app is running in the background

It is important to note that we should make sure that we configure the URLSessionConfiguration object appropriately before we use it to create an instance of the URLSession class. When the session object is created, it creates a copy of the configuration object that we provide. Any changes made to the configuration object once the session object is created are ignored by the session. If we need to make changes to the configuration, we must create another instance of the URLSession class.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset