For "normal" apps there is no way to know when a user terminates your app from the "recently-used-apps list" bar. "Normal" apps are iOS apps that do not opt out of background execution and apps that can't truly run in the background full-time (such as GPS and VOIP apps).
Once your app gets put in the background, it is possible the app can be terminated in one of two ways:
- The OS needs more resources
- The user uses the "recently-used-app list" to remove the app from the list
In both of these cases a normal app is simply killed. No notification of any kind is sent to the app.
Apps that are allowed to truly run in the background will be notified through the UIApplication applicationWillTerminate:
method and the UIApplicationWillTerminateNotification
notification.
Since normal apps are suspended when they enter the background, it is best to save data or persist any state when the app enters the background and assume the app could be terminated while suspended.
Also keep in mind that an app can appear in the "recently-used-apps list" even if it isn't running or suspended. If the OS kills a suspended app to use the resources for recent apps, the terminated app is still shown in the list. The user can still remove the app from the list at this point but the app is already terminated.