### PLCrashReporterConfig Initialization Source: https://context7.com/microsoft/plcrashreporter/llms.txt Demonstrates how to initialize PLCrashReporterConfig with different strategies for signal handling and symbolication, including Objective-C and Swift examples. ```APIDOC ## PLCrashReporterConfig `PLCrashReporterConfig` specifies the signal handler strategy and local symbolication options. Use `PLCrashReporterSignalHandlerTypeMach` for best coverage; use `PLCrashReporterSignalHandlerTypeBSD` for tvOS or when a managed runtime (Xamarin/Unity) is present. For release builds always pass `PLCrashReporterSymbolicationStrategyNone` to minimize crash-handler code surface; enable `PLCrashReporterSymbolicationStrategyAll` only for debug builds. ### Objective-C Examples ```objc @import CrashReporter; // Release configuration (recommended for App Store builds) PLCrashReporterConfig *releaseConfig = [[PLCrashReporterConfig alloc] initWithSignalHandlerType:PLCrashReporterSignalHandlerTypeMach symbolicationStrategy:PLCrashReporterSymbolicationStrategyNone]; // Debug configuration with full local symbolication PLCrashReporterConfig *debugConfig = [[PLCrashReporterConfig alloc] initWithSignalHandlerType:PLCrashReporterSignalHandlerTypeMach symbolicationStrategy:PLCrashReporterSymbolicationStrategyAll]; // Custom report storage path + uncaught exception handler opt-out (for Xamarin apps) NSString *customPath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"plcrash"]; PLCrashReporterConfig *xamarinConfig = [[PLCrashReporterConfig alloc] initWithSignalHandlerType:PLCrashReporterSignalHandlerTypeBSD symbolicationStrategy:PLCrashReporterSymbolicationStrategyNone shouldRegisterUncaughtExceptionHandler:NO basePath:customPath maxReportBytes:256 * 1024]; // 256 KB cap // Read back properties NSLog(@"Handler: %lu, BasePath: %@", (unsigned long)xamarinConfig.signalHandlerType, xamarinConfig.basePath); ``` ### Swift Examples ```swift import CrashReporter // Swift — release configuration let releaseConfig = PLCrashReporterConfig(signalHandlerType: .mach, symbolicationStrategy: []) // Swift — debug configuration let debugConfig = PLCrashReporterConfig(signalHandlerType: .mach, symbolicationStrategy: .all) // Default configuration (BSD handler, no symbolication) let defaultConfig = PLCrashReporterConfig.defaultConfiguration() ``` ``` -------------------------------- ### Install PLCrashReporter via Carthage Source: https://context7.com/microsoft/plcrashreporter/llms.txt Integrate PLCrashReporter using Carthage by adding it to your Cartfile and updating. ```ruby # Cartfile github "microsoft/plcrashreporter" ``` ```bash carthage update --use-xcframeworks # Drag CrashReporter.xcframework into Frameworks, Libraries and Embedded Content # iOS/tvOS: Do not embed | macOS: Embed and Sign ``` -------------------------------- ### Generate Proto C Files Source: https://github.com/microsoft/plcrashreporter/blob/master/README.md Run this script after modifying any .proto files to generate the necessary C descriptor code. Ensure you have protobuf-c installed. ```bash ./Dependencies/protobuf-c/generate-pb-c.sh ``` -------------------------------- ### Install PLCrashReporter via CocoaPods Source: https://context7.com/microsoft/plcrashreporter/llms.txt Add the PLCrashReporter pod to your Podfile for installation using CocoaPods. ```ruby # Podfile pod 'PLCrashReporter' ``` ```bash pod install ``` -------------------------------- ### Setup Crash Reporter in Objective-C Source: https://context7.com/microsoft/plcrashreporter/llms.txt Initializes PLCrashReporter with a Mach exception handler and no symbolication. It includes a helper to detect attached debuggers and registers an async-safe post-crash callback. Ensure not to enable the reporter while a debugger is attached. ```Objective-C @import CrashReporter; #import // Helper: detect attached debugger (from DemoCrash reference implementation) static BOOL isDebuggerAttached(void) { struct kinfo_proc info = {}; size_t info_size = sizeof(info); int name[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid() }; sysctl(name, 4, &info, &info_size, NULL, 0); return (info.kp_proc.p_flag & P_TRACED) != 0; } // Async-safe post-crash callback (called after report is written to disk) static void postCrashCallback(siginfo_t *info, ucontext_t *uap, void *context) { // MUST be async-safe — no Objective-C, no malloc, no locks // 'context' is the value set in PLCrashReporterCallbacks.context } - (void)setupCrashReporter { if (isDebuggerAttached()) return; PLCrashReporterConfig *config = [[PLCrashReporterConfig alloc] initWithSignalHandlerType:PLCrashReporterSignalHandlerTypeMach symbolicationStrategy:PLCrashReporterSymbolicationStrategyNone]; PLCrashReporter *reporter = [[PLCrashReporter alloc] initWithConfiguration:config]; // Register optional post-crash callbacks PLCrashReporterCallbacks cb = { .version = 0, .context = (__bridge void *)self, .handleSignal = postCrashCallback }; [reporter setCrashCallbacks:&cb]; // Attach custom data to every crash report (max ~64 KB recommended) reporter.customData = [@"session-id:abc-123" dataUsingEncoding:NSUTF8StringEncoding]; NSError *error; if (![reporter enableCrashReporterAndReturnError:&error]) { NSLog(@"Failed to enable crash reporter: %@", error); // error.domain == PLCrashReporterErrorDomain // error.code one of PLCrashReporterError enum values } } ``` -------------------------------- ### Setup Crash Reporter in Swift Source: https://context7.com/microsoft/plcrashreporter/llms.txt Configures PLCrashReporter with a Mach signal handler and no symbolication strategy. Custom data can be attached to crash reports. Ensure the reporter is enabled within a do-catch block to handle potential errors. ```Swift import CrashReporter func setupCrashReporter() { let config = PLCrashReporterConfig(signalHandlerType: .mach, symbolicationStrategy: []) guard let reporter = PLCrashReporter(configuration: config) else { return } reporter.customData = "build:42 user:anon".data(using: .utf8) do { try reporter.enableAndReturnError() } catch { print("Crash reporter error: \(error)") } } ``` -------------------------------- ### Add PLCrashReporter via CocoaPods Source: https://github.com/microsoft/plcrashreporter/blob/master/README.md Integrate PLCrashReporter into your project by adding the 'PLCrashReporter' pod to your Podfile and running 'pod install'. Ensure your project is opened as an .xcworkspace. ```ruby pod 'PLCrashReporter' ``` -------------------------------- ### Install PLCrashReporter via Swift Package Manager Source: https://context7.com/microsoft/plcrashreporter/llms.txt Add the PLCrashReporter Swift package dependency through Xcode's interface. ```swift File > Swift Packages > Add Package Dependency URL: https://github.com/microsoft/plcrashreporter.git Version: Up to Next Major from 1.12.2 ``` -------------------------------- ### Configure PLCrashReporterConfig for Release Builds (Swift) Source: https://context7.com/microsoft/plcrashreporter/llms.txt Create a release configuration in Swift using the Mach signal handler and no symbolication. ```swift import CrashReporter // Swift — release configuration let releaseConfig = PLCrashReporterConfig(signalHandlerType: .mach, symbolicationStrategy: []) ``` -------------------------------- ### Build PLCrashReporter Binaries Source: https://github.com/microsoft/plcrashreporter/blob/master/README.md Use xcodebuild to create release binaries for all platforms. This command should be run from the root folder of the PLCrashReporter project. ```bash xcodebuild -configuration Release -target 'CrashReporter' ``` -------------------------------- ### Generate Live Crash Report in Swift Source: https://context7.com/microsoft/plcrashreporter/llms.txt Generate a live snapshot of the current process using Swift. This method attempts to capture the report and format it as text, printing it to the console. Error handling is done via optional chaining. ```Swift import CrashReporter let reporter = PLCrashReporter(configuration: .defaultConfiguration())! // Live snapshot of the current process if let data = try? reporter.generateLiveReportAndReturnError(), let report = try? PLCrashReport(data: data), let text = PLCrashReportTextFormatter.stringValue(for: report, with: PLCrashReportTextFormatiOS) { print(text) } ``` -------------------------------- ### Enable Crash Reporter and Handle Errors (Objective-C) Source: https://context7.com/microsoft/plcrashreporter/llms.txt Demonstrates how to enable the crash reporter and handle potential errors using Cocoa's `NSError**` pattern. It also shows how to parse errors from corrupted report files. ```objc @import CrashReporter; NSError *error; PLCrashReporter *reporter = [[PLCrashReporter alloc] initWithConfiguration:[PLCrashReporterConfig defaultConfiguration]]; if (![reporter enableCrashReporterAndReturnError:&error]) { if ([error.domain isEqualToString:PLCrashReporterErrorDomain]) { switch (error.code) { case PLCrashReporterErrorOperatingSystem: NSLog(@"OS error: %@", error.userInfo[NSUnderlyingErrorKey]); break; case PLCrashReporterErrorResourceBusy: NSLog(@"Another crash reporter is already active"); break; case PLCrashReporterErrorCrashReportInvalid: NSLog(@"Existing crash report is corrupt"); break; default: NSLog(@"Unknown error: %@", error); } } } // Parse errors from corrupted report files NSData *data = [reporter loadPendingCrashReportDataAndReturnError:&error]; if (data) { PLCrashReport *report = [[PLCrashReport alloc] initWithData:data error:&error]; if (!report) { // error.code == PLCrashReporterErrorCrashReportInvalid for parse failures NSLog(@"Report parse failed: %@", error.localizedDescription); [reporter purgePendingCrashReport]; } } ``` -------------------------------- ### Configure PLCrashReporterConfig for Debug Builds (Swift) Source: https://context7.com/microsoft/plcrashreporter/llms.txt Create a debug configuration in Swift using the Mach signal handler and all symbolication options. ```swift import CrashReporter // Swift — debug configuration let debugConfig = PLCrashReporterConfig(signalHandlerType: .mach, symbolicationStrategy: .all) ``` -------------------------------- ### Convert .plcrash to Text Format (Bash) Source: https://context7.com/microsoft/plcrashreporter/llms.txt Uses the `plcrashutil` command-line tool to convert binary protobuf crash reports to Apple's iPhone text format. Output can be piped to `atos` for symbolication. ```bash # Convert a raw .plcrash file to iPhone text format plcrashutil convert --format=iphone example_report.plcrash # Symbolicate the output using atos # (requires the .dSYM bundle from the crashing build) plcrashutil convert --format=iphone example_report.plcrash | \ atos -arch arm64 -o MyApp.app.dSYM/Contents/Resources/DWARF/MyApp -l 0x100028000 # Typical output after symbolication: # Thread 0 Crashed: # 0 MyApp 0x00000001000283a4 -[ViewController crashButtonTapped:] (ViewController.m:42) # 1 UIKitCore 0x000000019aef1234 -[UIApplication sendAction:to:from:forEvent:] + 96 ``` -------------------------------- ### Access System, Machine, and Application Info Source: https://context7.com/microsoft/plcrashreporter/llms.txt Retrieves system, machine, process, and application information from a PLCrashReport. Requires PLCrashReport and may need v1.1+ reports for machine and process info. ```Objective-C PLCrashReport *report = [[PLCrashReport alloc] initWithData:data error:nil]; // System info (always present) PLCrashReportSystemInfo *sys = report.systemInfo; NSLog(@"OS: %ld version: %@ build: %@ timestamp: %@", (long)sys.operatingSystem, sys.operatingSystemVersion, sys.operatingSystemBuild ?: @"n/a", sys.timestamp); // Machine info (v1.1+ reports only) if (report.hasMachineInfo) { PLCrashReportMachineInfo *machine = report.machineInfo; NSLog(@"Model: %@ CPUs: %lu physical / %lu logical", machine.modelName ?: @"n/a", (unsigned long)machine.processorCount, (unsigned long)machine.logicalProcessorCount); NSLog(@"CPU type: %llu subtype: %llu", machine.processorInfo.type, machine.processorInfo.subtype); } // Process info (v1.1+ reports only) if (report.hasProcessInfo) { PLCrashReportProcessInfo *proc = report.processInfo; NSLog(@"Process: %@ (PID %lu) native: %@", proc.processName, (unsigned long)proc.processID, proc.native ? @"YES" : @"NO (Rosetta)"); NSLog(@"Parent: %@ (PID %lu)", proc.parentProcessName, (unsigned long)proc.parentProcessID); } // Application info PLCrashReportApplicationInfo *app = report.applicationInfo; NSLog(@"App ID: %@ version: %@ marketing: %@", app.applicationIdentifier, app.applicationVersion, app.applicationMarketingVersion ?: @"n/a"); // Custom data attached before the crash if (report.customData) { NSString *custom = [[NSString alloc] initWithData:report.customData encoding:NSUTF8StringEncoding]; NSLog(@"Custom data: %@", custom); } // Binary images for (PLCrashReportBinaryImageInfo *img in report.images) { NSLog(@" 0x%016llx – 0x%016llx %@ <%@>", img.imageBaseAddress, img.imageBaseAddress + img.imageSize, img.imageName.lastPathComponent, img.hasImageUUID ? img.imageUUID : @"no UUID"); } ``` -------------------------------- ### Add PLCrashReporter via Carthage Source: https://github.com/microsoft/plcrashreporter/blob/master/README.md Integrate PLCrashReporter using Carthage by adding the repository to your Cartfile and running 'carthage update --use-xcframeworks'. Follow the Xcode instructions for adding the xcframework. ```shell github "microsoft/plcrashreporter" ``` -------------------------------- ### Generate Live Crash Report in Objective-C Source: https://context7.com/microsoft/plcrashreporter/llms.txt Capture a protobuf crash report for the currently running process without crashing. This is useful for runtime diagnostics or attaching NSExceptions. Ensure mach/mach.h is imported for thread manipulation. ```Objective-C @import CrashReporter; #import PLCrashReporter *reporter = [[PLCrashReporter alloc] initWithConfiguration: [PLCrashReporterConfig defaultConfiguration]]; NSError *error; // Capture current thread NSData *liveData = [reporter generateLiveReportAndReturnError:&error]; // Capture a specific thread (e.g., a worker thread) thread_t workerThread = /* mach_thread_self() on target thread */ mach_thread_self(); NSData *threadData = [reporter generateLiveReportWithThread:workerThread error:&error]; // Attach a caught NSException to the report @try { [NSArray.new objectAtIndex:99]; } @catch (NSException *ex) { NSData *exData = [reporter generateLiveReportWithException:ex error:&error]; PLCrashReport *report = [[PLCrashReport alloc] initWithData:exData error:&error]; NSString *text = [PLCrashReportTextFormatter stringValueForCrashReport:report withTextFormat:PLCrashReportTextFormatiOS]; NSLog(@"Live report:\n%@", text); } ``` -------------------------------- ### Initialize PLCrashReporter in Swift Source: https://github.com/microsoft/plcrashreporter/blob/master/README.md Initializes the PLCrashReporter with custom configuration. Ensure the debugger is not attached when enabling in-process crash reporting. Local symbolication is recommended only for non-release builds. ```swift import CrashReporter ... // Uncomment and implement isDebuggerAttached to safely run this code with a debugger. // See: https://github.com/microsoft/plcrashreporter/blob/2dd862ce049e6f43feb355308dfc710f3af54c4d/Source/Crash%20Demo/main.m#L96 // if (!isDebuggerAttached()) { // It is strongly recommended that local symbolication only be enabled for non-release builds. // Use [] for release versions. let config = PLCrashReporterConfig(signalHandlerType: .mach, symbolicationStrategy: .all) guard let crashReporter = PLCrashReporter(configuration: config) else { print("Could not create an instance of PLCrashReporter") return } // Enable the Crash Reporter. do { try crashReporter.enableAndReturnError() } catch let error { print("Warning: Could not enable crash reporter: \(error)") } // } ``` -------------------------------- ### Configure PLCrashReporterConfig with Custom Path and Options (Objective-C) Source: https://context7.com/microsoft/plcrashreporter/llms.txt Configure the crash reporter with a custom report storage path, disable the uncaught exception handler (useful for Xamarin apps), and set a maximum report size. ```objective-c @import CrashReporter; // --- Objective-C --- // Custom report storage path + uncaught exception handler opt-out (for Xamarin apps) NSString *customPath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"plcrash"]; PLCrashReporterConfig *xamarinConfig = [[PLCrashReporterConfig alloc] initWithSignalHandlerType:PLCrashReporterSignalHandlerTypeBSD symbolicationStrategy:PLCrashReporterSymbolicationStrategyNone shouldRegisterUncaughtExceptionHandler:NO basePath:customPath maxReportBytes:256 * 1024]; // 256 KB cap // Read back properties NSLog(@"Handler: %lu, BasePath: %@", (unsigned long)xamarinConfig.signalHandlerType, xamarinConfig.basePath); ``` -------------------------------- ### Initialize PLCrashReporter in Objective-C Source: https://github.com/microsoft/plcrashreporter/blob/master/README.md Initializes the PLCrashReporter with custom configuration. Ensure the debugger is not attached when enabling in-process crash reporting. Local symbolication is recommended only for non-release builds. ```objc @import CrashReporter; ... // Uncomment and implement isDebuggerAttached to safely run this code with a debugger. // See: https://github.com/microsoft/plcrashreporter/blob/2dd862ce049e6f43feb355308dfc710f3af54c4d/Source/Crash%20Demo/main.m#L96 // if (![self isDebuggerAttached]) { // It is strongly recommended that local symbolication only be enabled for non-release builds. // 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); } // } ``` -------------------------------- ### Convert Crash Reports to iPhone Text Format Source: https://github.com/microsoft/plcrashreporter/blob/master/README.md Use the `plcrashutil` binary to convert protobuf-encoded crash reports to Apple's standard iPhone text format. This is useful for manual analysis or integration with other tools. ```ruby plcrashutil convert --format=iphone example_report.plcrash ``` -------------------------------- ### Handle Pending Crash Reports in Objective-C Source: https://context7.com/microsoft/plcrashreporter/llms.txt Use this snippet to load, parse, and then purge pending crash reports on application launch. Ensure the CrashReporter framework is imported. Upload the raw data before purging. ```Objective-C @import CrashReporter; - (void)handlePendingCrashReport:(PLCrashReporter *)reporter { if (![reporter hasPendingCrashReport]) return; NSError *error; // 1. Load raw protobuf bytes NSData *data = [reporter loadPendingCrashReportDataAndReturnError:&error]; if (!data) { NSLog(@ ``` ```Swift import CrashReporter func handlePendingReport(reporter: PLCrashReporter) { guard reporter.hasPendingCrashReport() else { return } defer { reporter.purgePendingCrashReport() } do { let data = try reporter.loadPendingCrashReportDataAndReturnError() let report = try PLCrashReport(data: data) print("Crashed:", report.systemInfo.timestamp ?? "unknown") print("Signal: \(report.signalInfo.name ?? "") at 0x\(String(report.signalInfo.address, radix: 16))") if report.hasExceptionInfo { print("Exception:", report.exceptionInfo.exceptionName ?? "", report.exceptionInfo.exceptionReason ?? "") } uploadCrashData(data) } catch { print("Failed to load/parse crash report:", error) } } ``` -------------------------------- ### Default PLCrashReporterConfig (Swift) Source: https://context7.com/microsoft/plcrashreporter/llms.txt Obtain the default configuration for PLCrashReporter in Swift, which uses the BSD signal handler and no symbolication. ```swift import CrashReporter // Default configuration (BSD handler, no symbolication) let defaultConfig = PLCrashReporterConfig.defaultConfiguration() ``` -------------------------------- ### Configure PLCrashReporterConfig for Release Builds (Objective-C) Source: https://context7.com/microsoft/plcrashreporter/llms.txt Use this configuration for release builds to minimize the crash-handler code surface. It employs the Mach signal handler and disables symbolication. ```objective-c @import CrashReporter; // --- Objective-C --- // Release configuration (recommended for App Store builds) PLCrashReporterConfig *releaseConfig = [[PLCrashReporterConfig alloc] initWithSignalHandlerType:PLCrashReporterSignalHandlerTypeMach symbolicationStrategy:PLCrashReporterSymbolicationStrategyNone]; ``` -------------------------------- ### Configure PLCrashReporterConfig for Debug Builds (Objective-C) Source: https://context7.com/microsoft/plcrashreporter/llms.txt Enable full local symbolication for debug builds to aid in debugging crashes. This configuration uses the Mach signal handler. ```objective-c @import CrashReporter; // --- Objective-C --- // Debug configuration with full local symbolication PLCrashReporterConfig *debugConfig = [[PLCrashReporterConfig alloc] initWithSignalHandlerType:PLCrashReporterSignalHandlerTypeMach symbolicationStrategy:PLCrashReporterSymbolicationStrategyAll]; ``` -------------------------------- ### Inspect Thread Backtraces and Registers Source: https://context7.com/microsoft/plcrashreporter/llms.txt Iterates through threads in a crash report, logging stack frames and register information for the crashed thread. Requires PLCrashReport. ```Objective-C PLCrashReport *report = [[PLCrashReport alloc] initWithData:data error:nil]; for (PLCrashReportThreadInfo *thread in report.threads) { NSLog(@"Thread %ld%@:", (long)thread.threadNumber, thread.crashed ? @" [CRASHED]" : @""); [thread.stackFrames enumerateObjectsUsingBlock: ^(PLCrashReportStackFrameInfo *frame, NSUInteger idx, BOOL *stop) { NSString *symbol = frame.symbolInfo.symbolName ?: @""; NSLog(@" #%lu 0x%016llx %@", (unsigned long)idx, frame.instructionPointer, symbol); }]; // Register dump (only present on the crashed thread) if (thread.crashed) { for (PLCrashReportRegisterInfo *reg in thread.registers) { NSLog(@" %-8@ 0x%016llx", reg.registerName, reg.registerValue); } } } // Look up the binary image for a given instruction pointer PLCrashReportStackFrameInfo *topFrame = [[report.threads.firstObject stackFrames] firstObject]; // firstObject is PLCrashReportThreadInfo PLCrashReportBinaryImageInfo *image = [report imageForAddress:topFrame.instructionPointer]; NSLog(@"Image: %@ UUID: %@", image.imageName, image.imageUUID); ``` ```Swift import CrashReporter for thread in report.threads as! [PLCrashReportThreadInfo] { print("Thread \(thread.threadNumber)\(thread.crashed ? " [CRASHED]" : "")") for (i, frame) in (thread.stackFrames as! [PLCrashReportStackFrameInfo]).enumerated() { let sym = frame.symbolInfo?.symbolName ?? "" print(String(format: " #%-3d 0x%016llx %@", i, frame.instructionPointer, sym)) } if thread.crashed { for reg in thread.registers as! [PLCrashReportRegisterInfo] { print(String(format: " %-8@ 0x%016llx", reg.registerName, reg.registerValue)) } } } ``` -------------------------------- ### Format Crash Reports to Text (Swift) Source: https://context7.com/microsoft/plcrashreporter/llms.txt Converts a parsed PLCrashReport to Apple's standard iPhone crash log format using a convenient class method. ```swift import CrashReporter let report = try PLCrashReport(data: data) // Quick class method if let text = PLCrashReportTextFormatter.stringValue(for: report, \ with: PLCrashReportTextFormatiOS) { print(text) } ``` -------------------------------- ### Check for Pending Crash Reports in Swift Source: https://github.com/microsoft/plcrashreporter/blob/master/README.md Checks if a crash report is pending, loads it, formats it as text, and then purges the report. Handles potential errors during loading and parsing. ```swift // Try loading the crash report. if crashReporter.hasPendingCrashReport() { do { let data = try crashReporter.loadPendingCrashReportDataAndReturnError() // Retrieving crash reporter data. let report = try PLCrashReport(data: data) // We could send the report from here, but we'll just print out some debugging info instead. if let text = PLCrashReportTextFormatter.stringValue(for: report, with: PLCrashReportTextFormatiOS) { print(text) } else { print("CrashReporter: can't convert report to text") } } catch let error { print("CrashReporter failed to load and parse with error: \(error)") } } // Purge the report. crashReporter.purgePendingCrashReport() ``` -------------------------------- ### Check for Pending Crash Reports in Objective-C Source: https://github.com/microsoft/plcrashreporter/blob/master/README.md Checks if a crash report is pending, loads it, formats it as text, and then purges the report. Handles potential errors during loading and parsing. ```objc if ([crashReporter hasPendingCrashReport]) { NSError *error; // Try loading the crash report. NSData *data = [crashReporter loadPendingCrashReportDataAndReturnError: &error]; if (data == nil) { NSLog(@"Failed to load crash report data: %@", error); return; } // Retrieving crash reporter data. PLCrashReport *report = [[PLCrashReport alloc] initWithData: data error: &error]; if (report == nil) { NSLog(@"Failed to parse crash report: %@", error); return; } // We could send the report from here, but we'll just print out some debugging info instead. NSString *text = [PLCrashReportTextFormatter stringValueForCrashReport: report withTextFormat: PLCrashReportTextFormatiOS]; NSLog(@"%@", text); // Purge the report. [crashReporter purgePendingCrashReport]; } ``` -------------------------------- ### Format Crash Reports to Text (Objective-C) Source: https://context7.com/microsoft/plcrashreporter/llms.txt Converts a parsed PLCrashReport to Apple's standard iPhone crash log format using either a class method for quick conversion or an instance method for streaming. ```objc @import CrashReporter; // Class method — quickest path PLCrashReport *report = [[PLCrashReport alloc] initWithData:data error:nil]; NSString *text = [PLCrashReportTextFormatter stringValueForCrashReport:report \ withTextFormat:PLCrashReportTextFormatiOS]; NSLog(@"%@", text); // Output example: // Incident Identifier: 5C1E9C9B-3C47-44B6-B1A2-... // CrashReporter Key: TODO // Hardware Model: iPhone14,2 // Process: MyApp [1234] // ... // Thread 0 Crashed: // 0 MyApp 0x000000010001c3a4 -[ViewController buttonTapped:] + 42 // ... // Instance method — for streaming into NSData via PLCrashReportFormatter protocol PLCrashReportTextFormatter *formatter = [[PLCrashReportTextFormatter alloc] initWithTextFormat:PLCrashReportTextFormatiOS stringEncoding:NSUTF8StringEncoding]; NSData *formattedData = [formatter formatReport:report error:nil]; [formattedData writeToFile:@"/tmp/crash.txt" atomically:YES]; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.