PLCrashReporter始终不返回崩溃日志

时间:2015-06-10 11:57:48

标签: ios xcode crash-reports plcrashreporter

我尝试使用PLCrashReporter捕获崩溃日志,并在下次应用启动时通过webservice发送。

代码:

- (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) {

    }];
    */
}

我总是将hasPendingCrashReport作为NO返回。我使用以下内容使应用程序崩溃:

  1. assert(0);

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

    [arr objectAtIndex:10];

  3. 请提前帮助我,

0 个答案:

没有答案