Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PLCrashReporter - How to convert .plcrash to .crash directly from Xcode itself and save it locally

I am currently working with PLCrashReporter and need some help with converting the plcrash directly to .crash file instead of using the plcrashutil.

What i currently do is -

I simulate a crash and it creates a myapp.plcrash file.

Once that is generated i use the following on command line -

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

This works perfectly - But is there a way I can dont have to do this extra step and convert it to .crash directly from my code probably by importing the library or something??

Any Solutions???

like image 785
vivianaranha Avatar asked Nov 16 '11 14:11

vivianaranha


1 Answers

Got the answer

Here is the solution if anyone else is looking for it..

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);
        }

    }
like image 153
vivianaranha Avatar answered Nov 10 '22 05:11

vivianaranha