Saturday, September 24, 2022
HomeiOS Developmentios - Updating the URLSessionConfiguration of a background URLSession

ios – Updating the URLSessionConfiguration of a background URLSession

How does one replace the configuration of a background session?

Taking a look at Apple’s documentation on URLSessionConfiguration

it says:

It is very important configure your URLSessionConfiguration object
appropriately earlier than utilizing it to initialize a session object. Session
objects make a duplicate of the configuration settings you present and use
these settings to configure the session. As soon as configured, the session
object ignores any modifications you make to the URLSessionConfiguration
object. If you might want to modify your switch insurance policies, you will need to replace
the session configuration object and use it to create a brand new URLSession

I additionally collect a static identifier is greatest, because it helps re-associate any operating duties ought to the app be terminated. I’ve seen in some posts folks have tried to create a UUID within the index and persist that: The way to revalidate the session as soon as it’s invalidated Alamofire? however that feels fairly fragile and cumbersome.

In my app, I wish to change whether or not the configuration permits downloading over mobile. Listed below are my steps:

  1. I cancel all activity – (I preserve a file of issues I wish to obtain afterward)
  2. I name invalidateAndCancel()
  3. I recreate the session by passing the up to date configuration.
  4. I attempt to create new duties from the record in level 1.

Nonetheless, this throws an error:

Activity created in a session that has been invalidated

Thanks upfront to your assist!



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments