PLCrashReporter - 如何直接从Xcode本身将.plcrash转换为.crash并将其保存在本地

时间:2011-11-16 14:49:36

标签: iphone crash plcrashreporter

我目前正在使用PLCrashReporter,需要一些帮助才能将plcrash直接转换为.crash文件,而不是使用plcrashutil。

我目前所做的是 -

我模拟了崩溃并创建了一个myapp.plcrash文件。

生成后,我在命令行中使用以下命令 -

plcrashutil convert --format=iphone myapp.plcrash > app.crash

这很有效 - 但是有没有办法我可以不必做这个额外的步骤并直接从我的代码转换为.crash可能是通过导入库或其他东西?

任何解决方案???

2 个答案:

答案 0 :(得分:16)

得到了答案

如果其他人正在寻找它,这是解决方案..

PLCrashReportTextFormat textFormat = PLCrashReportTextFormatiOS;


    /* Decode data */

    PLCrashReport *crashLog = [[PLCrashReport alloc] initWithData: data error: &error];
    if (crashLog == nil) {
        NSLog(@"Could not decode crash file :%@",  [[error localizedDescription] UTF8String]);
    } else {
        NSString* report = [PLCrashReportTextFormatter stringValueForCrashReport: crashLog withTextFormat: textFormat];
        NSLog(@"Crash log \n\n\n%@ \n\n\n", report);

        NSString *outputPath = [documentsDirectory stringByAppendingPathComponent: @"app.crash"];
        if (![report writeToFile:outputPath atomically:YES encoding:NSUTF8StringEncoding error:nil]) {
            NSLog(@"Failed to write crash report");
        } else {
            NSLog(@"Saved crash report to: %@", outputPath);
        }

    }

答案 1 :(得分:0)

您是否尝试过以新格式表示.crash文件?