3

Is there some type of notifications that iOS emits when app get force quited?

By force quite i mean tapping the home button while app is in active state and then removing it from multitasking menu.

I want to be able to detect force quit, to gracefully handle everything.

We have an issue like this with one of our games and our publisher wants us to handle this. This is not standard Cocoa App, this is game ported from PC, written mostly in C++.

This happens only on iPad Mini 2nd gen, when app is force quit-ed it will crash on next launch. On other devices, when app is activated it will load up properly and continue with proper scene loading order.

Does iPad mini 2nd gen has something different from other devices regarding development?

Crash logs says that app crashes immediately after force quit, well duh...

- (void)applicationWillTerminate:(UIApplication *)application is not really useful, it doesnt detect force app quit.

Martin Berger
  • 1,639
  • 3
  • 18
  • 39
  • No, there is no indication when the app is killed. – Paulw11 Jul 31 '14 at 09:32
  • possible duplicate of [How to know whether app is terminated by user or iOS (after 10min background)](http://stackoverflow.com/questions/7343404/how-to-know-whether-app-is-terminated-by-user-or-ios-after-10min-background) – dandan78 Jul 31 '14 at 09:33
  • possible duplicate of [applicationWillTerminate not getting called on force quit of iOS app](http://stackoverflow.com/questions/13386505/applicationwillterminate-not-getting-called-on-force-quit-of-ios-app) – Paulw11 Jul 31 '14 at 09:34
  • Please post the full crash report. – Kerni Jul 31 '14 at 11:34

1 Answers1

2

The idea is that your app should handle termination the same regardless of whether it was initiated by the operating system or by the user. You are encouraged to save the app's state and reload on the next start. And it's probably a good idea to save state when your app is sent to the background because according to the second paragraph below, applicationWillTerminate is not always called when the system kills your app.

According to the documentation

This method lets your app know that it is about to be terminated and purged from memory entirely. You should use this method to perform any final clean-up tasks for your app, such as freeing shared resources, saving user data, and invalidating timers.

Also

For apps that do not support background execution or are linked against iOS 3.x or earlier, this method is always called when the user quits the app. 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.

dandan78
  • 13,328
  • 13
  • 64
  • 78
  • I believe the issue is that in the case of kill from the app switcher the app does not receive any notification that it is about to die, however you are right - the crash on startup is the real issue that needs to be resolved – Paulw11 Jul 31 '14 at 09:51
  • Hm, it's interesting that the docs state that *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*. Strange – dandan78 Jul 31 '14 at 10:13
  • @dandan78 In my case `applicationWillTerminate` is not invoked. On my iPad4 iOS 6, when going to App Switcher and killing the app by pressing red x, such method is not invoked. I put a breakpoint in xcode there and it didnt break. I have tried putting NSLog and it also didnt work. – Martin Berger Jul 31 '14 at 10:24
  • The user kills the app with this interaction. The app will never receive any notification about that. – Kerni Jul 31 '14 at 11:33
  • @Kerni Thanks. I thought so. – Martin Berger Aug 01 '14 at 07:24