Add a Callback for App Crashes (setCrashCallback)

Use setCrashCallback (iOS only) to specify a callback function to run when the app crashes.

For example, use setCrashCallback to run a callback function which adds an entry to your app's log to save information used when reopening the app.

Before You Begin

Method Definition

In iOS, the Aternity class provides a static method called setCrashCallback:

+ (void)setCrashCallback:(AternityCrashReporterCallback)callback withContext:(void *)context;
Field Description
callback

Specify the name of the callback function to run if the app crashed. This callback function expects three parameters:

  • siginfo_t *info is a pointer to the structure which describes the caught signal.

  • ucontext_t *uap is the context of the thread which crashed before the signal arrived.

  • void *context is the app-specific context. Use this to pass any relevant information if needed.

Example

//Specify the callback function and parameter to run in the event of an app crash
[Aternity setCrashCallback:post_crash_callback withContext:(void *) 0xABABABAB];

//Define the callback function to run in the event of a crash
void post_crash_callback (siginfo_t *info, ucontext_t *uap, void *context) {
    NSLog(@"Detected crash: signo=%d, uap=%p, context=%p", info->si_signo, uap, context);
}