Search code examples
iosios7backgroundbackground-taskbackground-fetch

Background Fetch iOS - Terminated Apps


I think this might be answered quiet a few time, but still there are some unknown cases that I wanted to clarify.

I have been looking at Background Fetch API for one of my iOS application. I learned from several articles that fetchNewDataWithCompletionHandler will get called when OS decides to check if there is any new data from backend server(irrespective of what custom fetch interval we set). And the articles and tutorials says it will get called only if your application is in inactive/background/suspended state, not when user forcefully terminate the app from app switcher.

But my questions are;

  1. In WWDC 2013 video the instructor says:

There are two very important scenario to test, first scenario is when your app launched in background to fetch new content, and second one is your app resumed in background to fetch new content.

I think the second scenario is app resumed from background/suspended state. But what is this first scenario? From which state our app will "launch" in background to fetch data? From not running state?

  1. To test background fetch there are two options, one is to create new scheme with 'Launch due to background fetch' and other one is from debug / simulate background fetch. I think the second one is to simulate the background fetch when the application is in background or suspended. But what is the first case? Is it something about when application is not running(removed from app switcher)?

Any thoughts?

Thanks!!


Solution

  • The first case is when your app is not running at the time. iOS has decided that it is going to give your app some time to run, but your app hasn't been launched yet.

    This can happen if the phone was recently rebooted (and so your app has never been launched) or most likely if your app was killed because the memory was needed for something else. If the user launches lots of other large apps (e.g. games) then your app will eventually be evicted from memory.

    This will never happen if the user killed the app using app switcher; if the user killed the app, then iOS will not restart it because it is assumed that the user wants it to stay dead.