If the user kills the app manually while the app is not suspended, the applicationWillTerminate
will be called in your app delegate.
When the user just press the home button the applicationDidEnterBackground
is called in your app delegate.
If the applicationDidEnterBackground
is called, and the applicationWillTerminate
is not probably the app was not killed properly.
I said probably because there is no warranty that the applicationWillTerminate
is called in case of app kill. In fact if the app is suspended the method will not be called.
For apps that support background execution, this method is generally
not called when the user quits the app because the app simply moves to
the background in that case. However, this method may be called in
situations where the app is running in the background (not suspended)
and the system needs to terminate it for some reason.
source: https://developer.apple.com/reference/uikit/uiapplicationdelegate/1623111-applicationwillterminate
The scenario when a manual kill would not cause this method to be called is when the user push the home button, and after a while he double press the home button and kill the app. In this scenario iOS would call applicationDidEnterBackground
in your delegate when the user press the home button, and after ~5 seconds the app would get the status of suspended. When the user kills the app later on, its status would be suspended, and the willTerminate method would not be called.
the same happens if while suspended iOS kills the app to get resources giving to it the status of terminated.
What I would do is to persist the timeStamp of the applicationDidEnterBackground
method call, cancel it on applicationWillEnterForeground
and in the applicationWillTerminate
.
If the next time that your application(_:willFinishLaunchingWithOptions:)
gets called you have a value for the timestamp saved in the applicationDidEnterBackground
it means that the user did not manually kill the app (maybe) and he did not come back after putting it in background.
If the user killed the app while the app was suspended, maybe in your case it would still be considered a misuse of the app, and the message can be displayed, so that all the use case are covered.