Search code examples
iosobjective-cnsurlsessionnsurlsessiondownloadtask

Does NSUrlSession continue file transfer if the app is killed from task manager?


I have tried various samples from the web (the last one being this one) in order to get a better understanding of NSUrlSession.

What I was hoping to see: file downloads will continue even if the app that triggered them gets killed (for instance by the user through the task manager). However this does not seem to happen.

Is this a configuration issue or does background file transfer not work if the app gets terminated? I thought the whole idea was that iOS will restart the app.


Solution

  • If the system kills your app and your background session has active downloads, your downloads will continue and the system will launch your app when the downloads complete. However, if a user force quits your app, all tasks get cancelled.

    Documentation for backgroundSessionConfigurationWithIdentifier:

    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.