[英]Method called on crash iOS app
The problem is i want to send something to keychain right before my application will be terminated (and yes, i mean terminated - no in background). 问题是我想在我的应用程序终止之前立即将一些东西发送到钥匙串(是的,我的意思是终止-在后台不存在)。
I am pretty sure that AppDelegate
method: 我很确定
AppDelegate
方法:
- (void)applicationWillTerminate:(UIApplication *)application
works before on similar situations. 在类似情况下可以正常工作。 But now, this method is never called.
但是现在,从未调用过此方法。
I'm using Xcode 5 and develop for iOS 7.0 我正在使用Xcode 5并为iOS 7.0开发
I'm not sure that applicationWillTerminate:
is trigged when crashing. 我不确定崩溃时触发了
applicationWillTerminate:
:。
I call during didFinishLaunchingWithOptions:
: 我在
didFinishLaunchingWithOptions:
期间致电:
NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);
Then, in your appDelegate, add : 然后,在您的appDelegate中,添加:
void uncaughtExceptionHandler(NSException *exception) {
NSLog(@"CRASH: %@", exception);
NSLog(@"Stack Trace: %@", [exception callStackSymbols]);
// Internal error reporting
}
Maybe you could save something to keychain from this method. 也许您可以通过此方法将某些内容保存到钥匙串中。
For Swift 4 对于Swift 4
Right this code in didFinishLaunchingWithOptions()
: 在
didFinishLaunchingWithOptions()
修改此代码:
NSSetUncaughtExceptionHandler { exception in
print("Error Handling: ", exception)
print("Error Handling callStackSymbols: ", exception.callStackSymbols)
}
And any time when your app will crash then this block will be called. 每当您的应用崩溃时,都会调用此块。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.