Crash-Time Handler

When an application crashes, details about the app’s runtime state are gathered and prepared for submission to Instabug on the next launch. However, what if you want to run some code after generating the report? This is where the onCrashHandler kicks in.

The onCrashHandler hook enables you to run custom code after the crash report has been generated. The information then becomes accessible in the “User Data” section of the dashboard after the next launch, during the didSendCrashReportHandler phase.


Here's an example of the code to be called on a crashing session:

void onCrashedHandler(IBGCrashReportWriter *writer) {
    writer->addStringElement(writer, "test_key", "Value 1");
    writer->addIntegerElement(writer, "test_Int", 12321312);
    writer->addUIntegerElement(writer, "total_memory", [NSProcessInfo processInfo].physicalMemory);
    CFTimeInterval timeInSeconds = CFAbsoluteTimeGetCurrent() + kCFAbsoluteTimeIntervalSince1970;
    writer->addUIntegerElement(writer, "timestamp", (unsigned long)timeInSeconds);
}

It should also be set in the Instabug's Crash Reporter:

[IBGCrashReporting setOnCrashHandler:onCrashedHandler];
CrashReporting.onCrashHandler = onCrashedHandler

📘

Note:

  • Any function called within a signal handler must be asynchronous-safe. This means that Objective-C code, among others, is not safe to use in this context.
  • This is enabled through a Feature flag. So, please contact our support team at [email protected] to enable it