可通过注册NSUncaughtExceptionHandler捕获异常信息,将拿到的NSException细节写入crash日志,能够定位到出错程序位置,并且将crash信息上传到服务器。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSSetUncaughtExceptionHandler(&UncaughtExceptionHandler);
}
NSSetUncaughtExceptionHandler(NSException *exception){
NSArray *array = [exception callStackSymbols] ;//得到当前调用堆栈信息
NSString *reason = [exception reason] ; //得到崩溃的原因
NSString *name = [exception name];//异常类型
NSLog(@"exception type : %@ \n crash reason : %@ \n call stack info : %@", name, reason, arr);
};