简体   繁体   中英

how to know when my app has exited by removing it from iOS multi tasking bar

As you all know, when the user keeps pressing on the home button while showing the bottom multi-tasking bar (taskbar of the iOS), he can exit any application and remove it from the bar, how to check for this case for my application.

thanks in advance.

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:

  1. The OS needs more resources
  2. 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.

In the application delegate, implement the

- (void)applicationWillTerminate:(UIApplication *)app;

method. This is called when the application is quit (either by the OS or the user).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM