我正在使用以下代码在我的应用程序中捕获异常:
void uncaughtExceptionHandler(NSException *exception) {
[FlurryAPI logError:@"Uncaught" message:@"Crash!" exception:exception];
}
只是想知道我是否可以查明发生错误的行号、UIView
、类等。理想情况下,我希望获得尽可能多的详细信息,因为它是由 FlurryAPI
分析捕获的。
乱舞API: http://www.flurry.com/
最佳答案
我最终选择了这个:
void uncaughtExceptionHandler(NSException *exception) {
NSArray *backtrace = [exception callStackSymbols];
NSString *platform = [[UIDevice currentDevice] platform];
NSString *version = [[UIDevice currentDevice] systemVersion];
NSString *message = [NSString stringWithFormat:@"Device: %@. OS: %@. Backtrace:\n%@",
platform,
version,
backtrace];
[FlurryAPI logError:@"Uncaught" message:message exception:exception];
}
更新(基于下面@TommyG 的评论):
将 NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);
添加到 AppDelegate
中的 --(BOOL)application:didFinishLaunchingWithOptions:
方法的末尾。然后将上述方法也添加到 AppDelegate
中。
关于iphone - Objective-C/iPhone - NSException 捕获尽可能多的信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5500490/