如果我的应用在启动期间崩溃,我希望将其重置为标准设置。最好还是在上次运行时崩溃。

编辑: Crittercism 具有crittercismDidCrashOnLastLoad方法,但它仅处理在加载过程中崩溃的情况。在我使用的库版本中,它无法正常运行,但是此后已修复。

有什么建议吗?

最佳答案

AppDelegate.m文件中执行2个功能:

void HandleException(NSException *exception) {
    NSLog(@"App crashing with exception: %@", exception);
    //Save somewhere that your app has crashed.
}

void HandleSignal(int signal) {
    NSLog(@"We received a signal: %d", signal);
    //Save somewhere that your app has crashed.
}

然后在您的-(BOOL)application:didFinishLaunchingWithOptions中放任何其他内容:
NSSetUncaughtExceptionHandler(&HandleException);

struct sigaction signalAction;
memset(&signalAction, 0, sizeof(signalAction));
signalAction.sa_handler = &HandleSignal;

sigaction(SIGABRT, &signalAction, NULL);
sigaction(SIGILL, &signalAction, NULL);
sigaction(SIGBUS, &signalAction, NULL);

10-08 17:45