Will performFetchWithCompletionHandler be called if the app has been terminated?

Its surprisingly difficult to find a definitive answer to this. Its not stated if this is the case or not in the Apple documentation and I couldn't find a definite yes/no after searching the internet - most of the material contradicts each other.


The Apple documentation states "If you do not call the completion handler in time, your app is terminated". But that says nothing about if your app is launched into the background in the first place in order to perform the background fetch.


By stating this Apple implies your app must already be in the background in order for performFetchWithCompletionHandler to be called, but they don't specifically say so, and if that is the case then that is opposite of what this book says "If the application is not already running in the background when a fetch is scheduled to occur, it will be launched in the background by the operating system and the fetch delegate method called."

http://www.techotopia.com/index.php/IOS_7_Multitasking,_Background_Transfer_Service_and_Fetching#An_Overview_of_Background_Fetch


But searching the internet turns up results that say the opposite.



The question is simple - if the app requests a background fetch to be performed after N time, then if the user terminates the app. Will the OS still launch the app into the background to perform the background fetch at some point? Yes or no?


Thanks

Replies

The problem here is that terminated has two different meanings:

  1. The system terminating your app as part of the usual app lifecycle, that is, after the user has put it in the background

  2. The user removing your app from the multitasking UI

I suspect you’re using meaning 2, in which case the answer is, no, the system will not relaunch your app in the background. Removing an app from the multitasking UI is a strong indication by the user that they don’t want it running in the background. There are some limited circumstances where the system ignores that request — the exact list varies by background launch type and by OS version — but background fetch is not one of those.

The only way to clear this state is for the user to manually launch your app again.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"