I'd like to show a (local) notification to the user when my app is terminated, be it by iOS itself or by the user via the task switcher.
When iOS kills the app because of memory pressure the applicationWillTerminate
function is called on my AppDelegate
, so I can schedule a local notification in that case.
However, when the user kills the app by swiping it to the top in the task switcher, the applicationWillTerminate
function is not called (as stated in the Apple docs and various answers here on SO). And yet, there are apps that still do succeed in showing a (local) notification to the user in that case (especially fitness tracking apps, e.g. Human), asking the user to restart the app so the background tracking can continue.
I can think of some (mostly awkward, or at least battery consuming) ways to get this done, but is there a nice way to show such a notification to the user? Especially to do so almost instantly after the app is killed by the user, which excludes a lot of possible workarounds with scheduling and cancelling local notifications every n seconds in the background ...