iphone 异常捕获处理
1 void UncaughtExceptionHandler(NSException *exception) { 2 NSArray *arr = [exception callStackSymbols]; 3 NSString *reason = [exception reason]; 4 NSString *name = [exception name]; 5 NSString *urlStr = [NSString stringWithFormat:@"mailto://XXX@XXX.com?subject=bug报告&body=感谢您的配合!<br><br><br>" 6 "错误详情:<br>%@<br>--------------------------<br>%@<br>---------------------<br>%@", 7 name, 8 reason, 9 [arr componentsJoinedByString:@"<br>"]]; 10 NSURL *url = [NSURL URLWithString:[urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 11 [[UIApplication sharedApplication] openURL:url]; 12 }
然后在程序启动中加入异常捕获回调
1 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 2 { 3 // Override point for customization after application launch. 4 NSSetUncaughtExceptionHandler (&UncaughtExceptionHandler); 5 return YES; 6 }