When you create a background session, you do two things:
- Passing nsurlsessiond (background daemons) to create a session.
- Create a local session in the application connected to this session.
The purpose of the identifier is to allow your application to reconnect to an external session (controlled by nsurlsessiond) if your application ends with the operating system.
As far as I know, usually your application cannot voluntarily separate its session from the background session. Therefore, when your application tries to create a session with the same identifier, suddenly two sessions appear that try to talk to the same external session in nsurlsessiond, and everything goes wrong. This is not a supported way to use the API.
The background session object must be maintained throughout the life of your application. Do not try to get rid of it and recreate it in one run. You should never create a session with the same identifier unless your application restarts.
Please note that if your application restarts to process background events (iOS only), when you call the completion handler provided by the event, the local session of your application becomes invalid and you need to create it if your application does something after that. The only situation that I know about when a background session ceases to be associated with a background session in nsurlsessiond and therefore the only situation when you should ever create a session with the same identifier twice in one run (once when you're asked handle background events, and then potentially again when you get didFinishLaunching to indicate that the user has redirected your application).
source share