appDelegate中是否有任何方法在应用程序崩溃时调用

appDelegate中是否有任何方法在应用程序崩溃时调用

本文介绍了appDelegate中是否有任何方法在应用程序崩溃时调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当应用程序终止时,我需要在应用程序中保存一些数据,即使它崩溃了。我知道当应用程序终止时会调用 applicationWillTerminate ,但我不确定在应用程序崩溃时调用哪个方法。

有人可以帮助我吗?

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?

推荐答案

您可以添加自己的异常处理程序,以捕获错误。

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!

这篇关于appDelegate中是否有任何方法在应用程序崩溃时调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 16:14