虽然有了try catch异常捕获,但是还是存在崩溃异常无法捕获到的。我可以通过下面的方式来获取崩溃日志:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
//设置异常处理Handler
NSSetUncaughtExceptionHandler(&UncaughtExceptionHandler);
return YES;
}
void UncaughtExceptionHandler(NSException *exception) {
//下面代码可以获取到崩溃异常的相关信息
NSArray *callStack = [exception callStackSymbols];
NSString *reason = [exception reason];
NSString *name = [exception name];
//将收集到的崩溃日志进行处理,上报服务器或者提示用户邮件发送等等。。。
}
时间: 2024-10-09 22:40:34