这里不多说了,直接代码记录一下:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// if (/* DISABLES CODE */ (1)==1) @throw [NSException exceptionWithName:@"if name" reason:@"条件不成立" userInfo:nil];
@try {
// NSAssert(0==1, @"cuowu");
}
@catch (NSException *exception) {
@throw [NSException exceptionWithName:@"123" reason:@"fasonyicahng" userInfo:nil];
}
@finally {
}
_uncaught = NSGetUncaughtExceptionHandler();
NSSetUncaughtExceptionHandler(&UncaughtExceptionHandle);
return YES;
}
NSUncaughtExceptionHandler * _uncaught = nil;
void UncaughtExceptionHandle(NSException * exception){
/**
* 捕获异常
*
* @param void <#void description#>
*
* @return <#return value description#>
*/
NSArray * callBack = [exception callStackSymbols];
NSString * reason = [exception reason];
NSString * name = [exception name];
NSString * content = [NSString stringWithFormat:@"=====异常错误报告===\nname:%@ \n reason:\n %@ \n callBckStackSynbols:\n %@",name,reason,callBack ];
NSMutableString * mailUrl = [NSMutableString string];
[mailUrl appendString:@"mailto:123456@qq.com"];
[mailUrl appendString:@"?subject=程序异常崩溃,请配合发送异常报告,谢谢合作!"];
[mailUrl appendFormat:@"&body=%@",content];
//打开地址
// NSString * mailPath = [mailUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString * mailPath = [mailUrl stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:mailPath]];
}
NSSetUncaughtExceptionHandler 这个是一个c方法,工程有崩溃的地方都会在这个地方发送到邮箱