捕获异常

捕获异常

void uncaughtExceptionHandler(NSException *exception) {

/**

*  获取异常崩溃信息

*/

NSArray *callStack = [exception callStackSymbols];

NSString *reason = [exception reason];

NSString *name = [exception name];

NSString *content = [NSString stringWithFormat:@"========异常错误报告========\nname:%@\nreason:\n%@\ncallStackSymbols:\n%@",name,reason,[callStack componentsJoinedByString:@"\n"]];

/**

*  把异常崩溃信息发送至开发者邮件

*/

NSMutableString *mailUrl = [NSMutableString string];

[mailUrl appendString:@"mailto:[email protected]"];

[mailUrl appendString:@"?subject=程序异常崩溃,请配合发送异常报告,谢谢合作!"];

[mailUrl appendFormat:@"&body=%@", content];

// 打开地址

NSString *mailPath = [mailUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:mailPath]];

}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);

}

你可能感兴趣的:(捕获异常)