Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any method in appDelegate which is called when application crashes?

Tags:

ios

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?

like image 556
Nitish Avatar asked Feb 13 '12 10:02

Nitish


1 Answers

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!

like image 65
rckoenes Avatar answered Oct 01 '22 17:10

rckoenes