设置崩溃报告

全局捕获异常的小工具,在App崩溃前可以捕获到异常,可以直接打印,也可以保存到沙盒,这样便于下次启动App时将异常报告发送给服务端。

void uncaughtExceptionHandler(NSException *exception) {
    NSString *name = exception.name;
    NSString *reason = exception.reason;
    NSArray *callStackSymbols = exception.callStackSymbols;
    NSString *exceptionReport = [NSString stringWithFormat:@"=============异常崩溃报告=============\nname:\n%@\nreason:\n%@\ncallStackSymbols:\n%@",
                                 name, reason, [callStackSymbols componentsJoinedByString:@"\n"]];
    NSLog(@"%@", exceptionReport);
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    // 设置捕获异常
    NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);
    
    return YES;
}

你可能感兴趣的:(设置崩溃报告)