Nitish
Nitish

Reputation: 14113

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

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

Answers (2)

rckoenes
rckoenes

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

Ilanchezhian
Ilanchezhian

Reputation: 17478

No, you cannot get to know when the application crashes.

Upvotes: -5

Related Questions