检测应用程序在加载/上次运行期间崩溃了吗? [英] Detect app crashed during load / last time it was run?

查看:154
本文介绍了检测应用程序在加载/上次运行期间崩溃了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我的应用在启动过程中崩溃,我希望将其重置为标准设置。 最好也是如果它在上次运行时崩溃

I would like for my app to reset to standard settings if it crashed during startup. Preferably also if it crashed last time it was run.

编辑: Crittercism 有一个 crittercismDidCrashOnLastLoad 方法,但它只处理加载期间崩溃的情况。它在我使用的库版本中无法正常工作,但此后已修复。

Crittercism has a crittercismDidCrashOnLastLoad method, but it only handles the case of crashing during load. It didn't work properly in the version of the library I used, but this has since been fixed.

建议?

推荐答案

AppDelegate.m 文件中创建2个函数:

Make 2 functions in your AppDelegate.m file:

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)应用程序中:didFinishLaunchingWithOptions 之前放入任何其他内容:

Then in your -(BOOL)application:didFinishLaunchingWithOptions before anything else put:

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);

这篇关于检测应用程序在加载/上次运行期间崩溃了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆