PLCrashReporter always returns no crash log

766 views Asked by At

I'm trying to capture crash log using PLCrashReporter and send it via webservice on next App launch.

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'm always getting return of hasPendingCrashReport as NO. I made the App crash using following :

  1. assert(0);

  2. NSArray * arr = [[NSArray alloc] init];

    [arr objectAtIndex:10];

Please help me with this, thanks in advance

0

There are 0 answers