用苹果提供的api NSSetUncaughtExceptionHandler进行捕获
void CustomExceptionHandlers(NSException *exception){
NSMutableDictionary *userInfo= [NSMutableDictionary dictionaryWithDictionary:[exception userInfo]];
[userInfo setObject:exception.callStackSymbols forKey:@"CallstackSymbolsKey"];
[userInfo setObject:[exception name] forKey:@"NameKey"];
[userInfo setObject:[exception reason] forKey:@"ReasonKey"];
NSLog(@"%@",userInfo);
//可以在这个位置进行一些操作,比如保存或上传等,可以将堆栈信息一起上传
}
+(void)uncaughtSignalExceptionHandler {
NSSetUncaughtExceptionHandler(&CustomExceptionHandlers);
}
uncaughtSignalExceptionHandler 可在项目启动时进行调用