PLCrashReporter never returns crash log

I am trying to capture the crash log using PLCrashReporter

and send it via webservice the next time I start my application.

Code:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    //[self checkChrash];

    PLCrashReporter *crashReporter = [PLCrashReporter sharedReporter];


    BOOL value = [crashReporter hasPendingCrashReport];
    if (value)
        [self handleCrashReport];

   BOOL val=  [crashReporter enableCrashReporterAndReturnError:nil];


    return YES;
}




#pragma mark - Crash Reports

- (void)handleCrashReport
{
    PLCrashReporter *crashReporter = [PLCrashReporter sharedReporter];
    NSData *crashData;
    NSError *error;

    crashData = [crashReporter loadPendingCrashReportDataAndReturnError:&error];
    PLCrashReport *report = [[PLCrashReport alloc] initWithData:crashData error:nil];

    if (!crashData || !report) {

        [crashReporter purgePendingCrashReport];

    } else {

        NSString *stringRepresentation = [PLCrashReportTextFormatter stringValueForCrashReport:report withTextFormat:PLCrashReportTextFormatiOS];
        [self sendDataOnLatestCrashToServer:stringRepresentation];
        [crashReporter purgePendingCrashReport];
    }
}

- (void)sendDataOnLatestCrashToServer:(NSString *)crashString
{
   /* NSDictionary *params = @{
                             @"StackTrace" : crashString
                             // Add more parameters as you want
                             };
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:params options:NSJSONWritingPrettyPrinted error:nil];

    NSURL *url = [NSURL URLWithString:@"http://www.YOURRESTSERVER.com"];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20.0f];

    [request setHTTPMethod:@"POST"];
    [request addValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    [request setHTTPBody:jsonData];
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {

    }];
    */
}

      

I always get return hasPendingCrashReport as NO. I made the application crash using the following:

  • assert(0);

  • NSArray * arr = [[NSArray alloc] init];

    [arr objectAtIndex:10];

Please help me, thanks in advance

+3


source to share





All Articles