Reputation: 14113
I need to save some data in my application, when the application terminates and even if it crashes. I know that applicationWillTerminate
is called when application terminates but I am not sure which method is called when application crashes.
Can someone help me here?
Upvotes: 12
Views: 5007
Reputation: 69469
Well you could add your own exception handler, to catch the error.
First you need to define the exception method:
void uncaughtExceptionHandler(NSException *exception) {
// You code here, you app will already be unload so you can only see what went wrong.
}
Then tell the app to use your exception handler:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);
// The rest if you code ....
}
There is no way to make the app save data on crashing, since saving could be the reason for the crash!
Upvotes: 16