Reputation: 305
I'm currently building an app that supports background modes. To name a few, I've registered for background delivery for HealthKit
and I'm also montoring for location background events such as didEnterRegion
. As I know, if these are called, iOS will temporarily re-launch the app in the background. However, once this is finished, will applicationWillTerminate
be called from the background? If not, is there a way to listen for the app to terminate?
Upvotes: 1
Views: 2010
Reputation: 10152
Not always!
There are many many reason that cause your app to stop. For example: when system will kill process of your app unexpectedly or for apps that support background execution applicationWillTerminate()
will not get called. You do not know when your app fall into this case so you CANNOT rely on this method.
Base on this Apple's document:
For applications that support background execution, this method is generally not called when the user quits the application because the application simply moves to the background in that case. However, this method may be called in situations where the application is running in the background (not suspended) and the system needs to terminate it for some reason
For more information: There is already a S.O question discuss about when this method is called and when not.
Upvotes: 1
Reputation: 2488
No it will not. applicationWillterminate
is only called in apps that support background modes when the system needs to terminate it for some reason (memory, normally) if it's not suspended. If it's suspended, the system doesn't send any kind of notification to the app.
You can see more in-depth documentation about the App Life Cycle here: The App Life Cycle Documentation
Upvotes: 1
Reputation: 131408
Apps can be suspended at any time, and once they are suspended they can be terminated without further warning. Thus you can't rely on getting an applicationWillTerminate
. I believe you will get such a message if your app is actively running (foreground or background) at the time it's terminated, but I'm not certain of that. I am certain that you can't depend getting a terminate message.
Upvotes: 0