- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在尝试将 Matt Gallagher 的全局异常处理程序添加到我的一个项目中。运行位于 :
的示例项目http://cocoawithlove.com/2010/05/handling-unhandled-exceptions-and.html
我遇到了一个问题,即我按下“退出”但应用程序没有退出。它只是让我回到应用程序。我尝试使用 kill() 调用终止应用程序,但无法让应用程序退出。
来自 alertview 的回调似乎只处理 Continue 情况,不处理强制应用退出。
- (void)alertView:(UIAlertView *)anAlertView clickedButtonAtIndex:(NSInteger)anIndex
{
if (anIndex == 0)
{
dismissed = YES;
}
}
我知道应用程序本身不能自行退出,但在这种情况下,如果应用程序崩溃,我希望用户按下“退出”按钮并退出应用程序。
谢谢!
最佳答案
Apple 不相信退出按钮。但是您可以抛出另一个您未捕获的异常,导致您的应用程序崩溃,但如果您的应用程序崩溃,则它不会获得批准。
我认为最接近的方法是通过在您的 info.plist 中将 UIApplicationExitsOnSuspend 设置为 true 来禁用后台运行,然后按下主页按钮将退出您的应用程序。在这种情况下,您可以将退出按钮设为指向任何其他应用的链接。
将 if 语句更改为始终引发异常应该会使您的应用崩溃并退出。
- (void)handleException:(NSException *)exception
{
[self validateAndSaveCriticalApplicationData];
UIAlertView *alert =
[[[UIAlertView alloc]
initWithTitle:NSLocalizedString(@"Unhandled exception", nil)
message:[NSString stringWithFormat:NSLocalizedString(
@"You can try to continue but the application may be unstable.\n\n"
@"Debug details follow:\n%@\n%@", nil),
[exception reason],
[[exception userInfo] objectForKey:UncaughtExceptionHandlerAddressesKey]]
delegate:self
cancelButtonTitle:NSLocalizedString(@"Quit", nil)
otherButtonTitles:NSLocalizedString(@"Continue", nil), nil]
autorelease];
[alert show];
CFRunLoopRef runLoop = CFRunLoopGetCurrent();
CFArrayRef allModes = CFRunLoopCopyAllModes(runLoop);
while (!dismissed)
{
for (NSString *mode in (NSArray *)allModes)
{
CFRunLoopRunInMode((CFStringRef)mode, 0.001, false);
}
}
CFRelease(allModes);
NSSetUncaughtExceptionHandler(NULL);
signal(SIGABRT, SIG_DFL);
signal(SIGILL, SIG_DFL);
signal(SIGSEGV, SIG_DFL);
signal(SIGFPE, SIG_DFL);
signal(SIGBUS, SIG_DFL);
signal(SIGPIPE, SIG_DFL);
[exception raise];
}
关于iOS - UncaughtExceptions 全局异常处理程序不允许应用程序退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4350170/
我正在尝试将 Matt Gallagher 的全局异常处理程序添加到我的一个项目中。运行位于 : 的示例项目 http://cocoawithlove.com/2010/05/handling-unh
我正在学习错误/异常处理,但我不明白如何使用 process.on('uncaughtException', ...)。你能像 try 和 catch 一样使用它吗,还是它只处理异常? 最佳答案 如
升级到 Protractor 4.0.0 并根据重大更改调整配置后,我们终于启动了测试。 现在,问题是在测试运行后它失败了: [09:52:22] E/launcher - "process.on('
我发现了这个 Android: How to auto-restart application after it's been "force closed"? 但我不知道警报管理器应该放在哪里以及如何
好吧,这有点令人困惑,所以请留在此处 我有一个工作线程,它是 Node.js child_process,以 fork() 启动 工作进程从父进程接收消息,执行一些工作,然后在完成后发回消息。我的目标
我正在使用Selenium进行iOS移动应用测试。我正在使用各自 Appium version 1.3.7 Node JS version 2.7.5 ios webkit debug proxy i
请耐心等待,因为我是 Objective-C 语言的新手。我正在尝试初始化 initWithName() 方法,但它不起作用。我不确定为什么当我在这里查看其他答案时,它指出 .m 和 .h 文件必须在
当出现未捕获的异常时,我想从我的 UncaughtExceptionHandler 开始一个新 Activity 。这可能吗? 我认为当前 Activity 无法在其“错误”状态下启动新的子 Acti
我使用 process.on "uncaughtException"。有时我会多次调用它,因为它不是微不足道的模块系统。所以我得到警告: (node) warning: possible EventE
使用时,我有一个 nodeJS 项目在我的本地运行良好 process.on('uncaughtException', function (err) { console.log('********
我在 ES6 模块中有一个奇怪的行为: index.mjs: process.on('uncaughtException', err => { console.log('Oh no!'); p
我很好奇,因为 process.exit(1) 是否在异步回调中操作,appendFile,如果原来的错误发生的地方将继续运行并处于不稳定状态。我尝试将 process.exit(1) 与 fs 内联
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: Using global exception handling with “setUncaughtExcep
将已检查的异常直接丢弃到 UncaughtExceptionHandler 的负面后果是什么? Thread t = new Thread() { @Overr
结合a previous question我的,我想知道当异常被 Thread.UncaughtExceptionListener 捕获时,上下文到底发生了什么。当监听器接收到未捕获的异常时,上下文似
我正在尝试获取回溯符号,如下所示的 Xcode 列表 *** First throw call stack: ( 0 CoreFoundation
如果错误,我想在请求中 res.end('server error') 。我的代码: http.createServer(function(req,res){ process.on('uncaug
如果你在 node.js 中捕获了 uncaughtExceptions,像这样: process.on('uncaughtException', function (error) { conso
本文整理了Java中org.apache.hadoop.yarn.YarnUncaughtExceptionHandler.uncaughtException()方法的一些代码示例,展示了YarnUn
本文整理了Java中org.joda.time.tz.ZoneInfoProvider.uncaughtException()方法的一些代码示例,展示了ZoneInfoProvider.uncaugh
我是一名优秀的程序员,十分优秀!