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 }
参考:http://hi.baidu.com/suifeng_89/item/49c70e8a9d88b453850fab08