1. 在didFinishLaunchingWithOptions:(NSDictionary *)launchOptions方法中添加:
//將沙盒中的崩潰信息傳給服務(wù)器
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(@"崩潰日志上傳失敗");
}];
}
//設(shè)置捕捉異常的回調(diào)
NSSetUncaughtExceptionHandler(&handleException);
2. 在AppDelegate.m中實(shí)現(xiàn)方法handleException
//攔截異常
void handleException (NSException *exception){
NSMutableDictionary *info = [NSMutableDictionary dictionary];
a. info[@"callStack"] = [exception callStackSymbols];//調(diào)用棧信息
b. info[@"name"] = [exception name];//異常名字
c. info[@"reason"] = [exception reason];//異常描述
d. [[NSUserDefaults standardUserDefaults] setObject:info forKey:@"appCrashLog"];
}
3. 崩潰統(tǒng)計(jì):友盟、Flurry、Crashlytics