To use PLCrashReporter in Objective-C, import the module, configure the signal handler and symbolication strategy, and enable the reporter. Note that enabling in-process crash reporting may conflict with attached debuggers.
@import CrashReporter;
// Configure: Use PLCrashReporterSignalHandlerTypeMach and a symbolication strategy
// Use PLCrashReporterSymbolicationStrategyNone for release versions.
PLCrashReporterConfig *config = [[PLCrashReporterConfig alloc] initWithSignalHandlerType: PLCrashReporterSignalHandlerTypeMach
symbolicationStrategy: PLCrashReporterSymbolicationStrategyAll];
PLCrashReporter *crashReporter = [[PLCrashReporter alloc] initWithConfiguration: config];
// Enable the Crash Reporter.
NSError *error;
if (![crashReporter enableCrashReporterAndReturnError: &error]) {
NSLog(@"Warning: Could not enable crash reporter: %@", error);
}
// Checking for and processing a pending report
if ([crashReporter hasPendingCrashReport]) {
NSData *data = [crashReporter loadPendingCrashReportDataAndReturnError: &error];
if (data != nil) {
PLCrashReport *report = [[PLCrashReport alloc] initWithData: data error: &error];
if (report != nil) {
NSString *text = [PLCrashReportTextFormatter stringValueForCrashReport: report withTextFormat: PLCrashReportTextFormatiOS];
NSLog(@"%@", text);
}
}
[crashReporter purgePendingCrashReport];
}