Search code examples
iosnsurlsessionnsurlsessiondownloadtaskbackground-fetch

NSURLSessionDownloadTask continue downloading even if user kills the App


In Background Fetch Utility, data polling occurs when the app is in the background, suspended or not running state. If it is suspended, the system wakes it in order to run the background tasks. If it’s not running, the app is launched in the background. Thus, the system wakes my App and automatically pulls the data.

But, my requirement is different but little bit matching. I don't know how would I link up both the things. I am using NSURLSessionDownloadTask to download a file and it resumes on next launch with no problems at all. But, my downloading should be continue even if user quits the App. I know Background Fetch and NSURLSessionDownloadTaskare completely different things, but I really don't have any clue on how to achieve that?

Is it feasible ? If yes, how would I do it?


Solution

  • Once an App is killed, nothing happens. No code is executed. The only time we can start a download progress is with background fetch and that only happens at times determined by the OS.

    Background Fetch Utility just wakes up App for a moment, OS gives us limited time (10 seconds) to do a task like update data by requesting a server. How often our App would wake up ? — That time may defined by OS or by us.

    Conclusion: We can't continue downloading when App is killed. We can use Background Fetch Utility to download a file periodically within the time frame of 10 seconds. But, continuous downloading in background is not possible..