0

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.

JAHelia
  • 6,934
  • 17
  • 74
  • 134

2 Answers2

3

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.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
0

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).

  • 1
    According to [this question](http://stackoverflow.com/questions/7818045/applicationwillterminate-when-is-it-called-and-when-not), `-applicationWillTerminate:` won't always be called under all conditions when the application is in the background. – Kitsune Jan 26 '13 at 16:31
  • @Kitsune Neither will it, when e. g. a truck drives through the phone and the entire OS terminates suddenly :P This is the answer what OP is looking for. –  Jan 26 '13 at 16:32
  • 2
    Just doing a quick check with actual code (on both iOS 6 simulator/a real device) and I could never get `-applicationWillTerminate:` to be called when force-closing an app using the multitasking bar, which is consistent with comments made in the thread I linked to. – Kitsune Jan 26 '13 at 16:48
  • Now you stop downvoting without reason. ***Now.*** –  Jan 28 '13 at 18:02