PLCrashReporter使用

来源:互联网 发布:北京炫彩网络印刷 编辑:程序博客网 时间:2024/05/17 00:53
在didFinishLaunchingWithOptions里面调用init_crash_reporter。如果直接上传崩溃文件好查看些,要转换就麻烦了。


void save_crash_report (PLCrashReporter *reporter)
{
    if (![reporter hasPendingCrashReport])
        return;


    NSFileManager *fm = [NSFileManager defaultManager];
    NSError *error;
    
    NSString *path = [[Util getUserFile:@"CrashReport"] stringByAppendingPathComponent:getAppInfo()];
    
    NSData *data = [[PLCrashReporter sharedReporter] loadPendingCrashReportDataAndReturnError: &error];
    if (data == nil) {
        CLS_LOG(@"Failed to load crash report data: %@", error);
        return;
    }
    
    BOOL exsist = [fm fileExistsAtPath:path];
    NSError *err;
    if (exsist) {
        [fm removeItemAtPath:path error:&err];
    }else{
        [data writeToFile: path atomically: YES];
    }
    
    CLS_LOG(@"Saved crash report to: %@", path);


}




void init_crash_reporter()
{


    PLCrashReporter *crashReporter = [PLCrashReporter sharedReporter];
    
    NSError *error;
    
    /* Save any existing crash report. */
    save_crash_report(crashReporter);
    
    
    /* Enable the crash reporter */
    if (![crashReporter enableCrashReporterAndReturnError: &error]) {
        CLS_LOG(@"Could not enable crash reporter: %@", error);
    }
    
    /* Add another stack frame */
    //stackFrame();
}
0 0