iosnsurlsessionnsurlsessiondownloadtasknsurlsessionconfigurationnsurlsessiontask

NSURLsession background transfer service for download task, can it work even when App is suspended?


Before asking a question, let me clarify what I understand about iOS App states:


Backgrounded: In this state, your app is not in the foreground anymore but it is still able to run code.

Suspended: Your app enters this state when it’s no longer able to run code.


Now, I wanted to keep downloading going on when App is in background, i.e. it still does exist in multitasking screen. It is working as expected with background transfer service.

But, in some tutorial reference, I have read that you can perform downloading even when App is Backgrounded / Suspended. Can it work even when my App is suspended, i.e. removed from multitasking screen ?

I have been reading many documents including Apple class reference regarding background transfer service with download task, but no one clarifies that the download will not work when App is suspended (killed).

Appreciate your thoughts and advices !!!


Solution

  • If your app has been suspended by the system (without force quiting from multitasking screen) your background session will continue to work.

    If you force quit the application all download tasks will be canceled.

    The following is from backgroundSessionConfigurationWithIdentifier(_:) documentation :

    If an iOS app is terminated by the system and relaunched, the app can use the same identifier to create a new configuration object and session and retrieve the status of transfers that were in progress at the time of termination. This behavior applies only for normal termination of the app by the system. If the user terminates the app from the multitasking screen, the system cancels all of the session’s background transfers. In addition, the system does not automatically relaunch apps that were force quit by the user. The user must explicitly relaunch the app before transfers can begin again.