1. 在didFinishLaunchingWithOptions:(NSDictionary *)launchOptions方法中添加:
//将沙盒中的崩溃信息传给服务器
NSString *crashStr = [[NSUserDefaults standardUserDefaults] objectForKey:@"appCrashLog"];
if(crashStr && crashStr.length != 0)
{
[[LQSystemServer share]updataSystemCrashLogContent:crashStr success:^(id json) {
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"appCrashLog"];
NSLog(@"崩溃日志上传成功");
} failure:^(NSError *error) {
NSLog(@"崩溃日志上传失败");
}];
}
//设置捕捉异常的回调
NSSetUncaughtExceptionHandler(&handleException);
2. 在AppDelegate.m中实现方法handleException
//拦截异常
void handleException (NSException *exception){
NSMutableDictionary *info = [NSMutableDictionary dictionary];
a. info[@"callStack"] = [exception callStackSymbols];//调用栈信息
b. info[@"name"] = [exception name];//异常名字
c. info[@"reason"] = [exception reason];//异常描述
d. [[NSUserDefaults standardUserDefaults] setObject:info forKey:@"appCrashLog"];
}
3. 崩溃统计:友盟、Flurry、Crashlytics
网友评论