Martin Berger
Martin Berger

Reputation: 1708

iOS What is the proper way to handle force app quitting

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.

Upvotes: 3

Views: 2571

Answers (1)

dandan78
dandan78

Reputation: 13894

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.

Upvotes: 2

Related Questions