How does one replace the configuration of a background session?
Taking a look at Apple’s documentation on
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:
- I cancel all activity – (I preserve a file of issues I wish to obtain afterward)
- I name
- I recreate the session by passing the up to date configuration.
- 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!