程序异常退出时发送邮件报告的代码

void UncaughtExceptionHandler(NSException *exception) {

NSArray *arr = [exception callStackSymbols];

NSString *reason = [exception reason];

NSString *name = [exception name];

NSString *urlStr = [NSString stringWithFormat:@"mailto://[email protected]?subject=bug报告&body=感谢您的配合!<br><br><br>"

"错误详情:<br>%@<br>--------------------------<br>%@<br>---------------------<br>%@"

name,reason,[arr componentsJoinedByString:@"<br>"]];

NSURL *url = [NSURL URLWithString:[urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

[[UIApplication sharedApplication] openURL:url];

}



  在delegate文件里面- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions函数里面添加NSSetUncaughtExceptionHandler(&UncaughtExceptionHandler);  就可以了



原文出处:http://blog.sina.com.cn/s/blog_6a2cbc930100wb5o.html

你可能感兴趣的:(ios,程序异常)