Identifying crashes at launch

If your app crashes whilst it is launching, you may want to give the crash more attention. Bugsnag provides an API to mark events that occur during startup and also allows you to detect recurrent launch crashes.

Controlling the launch period

By default, Bugsnag will treat crashes that occur during the first 5 seconds after calling Bugsnag.start() as having occurred during launch.

Events that occur during the app launch have their app.isLaunching property set to true.

You can modify the launch time period using the launchDurationMillis configuration option.

BugsnagConfiguration *config = [BugsnagConfiguration loadConfig];
config.launchDurationMillis = 2000;
[Bugsnag startWithConfiguration:config];
let config = BugsnagConfiguration.loadConfig()
config.launchDurationMillis = 2000
Bugsnag.start(with: config)

You can also indicate that your app has finished launching by calling Bugsnag.markLaunchCompleted().

[Bugsnag markLaunchCompleted];
Bugsnag.markLaunchCompleted()

You can disable the automatic ending of the launch period by setting launchDurationMillis to 0 - in this case the app will be considered to be launching until Bugsnag.markLaunchCompleted() is called.

BugsnagConfiguration *config = [BugsnagConfiguration loadConfig];
config.launchDurationMillis = 0;
[Bugsnag startWithConfiguration:config];

// Once your app has finished launching;
[Bugsnag markLaunchCompleted];
let config = BugsnagConfiguration.loadConfig()
config.launchDurationMillis = 0
Bugsnag.start(with: config)

// Once your app has finished launching;
Bugsnag.markLaunchCompleted()

Sending launch crashes

If the previous run of your app crashed during app launch, Bugsnag.start() will block the calling thread for up to 2 seconds to allow the crash report to be sent before the app continues launching. In cases where a launch crash is persistent, this improves the reliability of crash reporting.

This behaviour can be disabled using the sendLaunchCrashesSynchronously option.

BugsnagConfiguration *config = [BugsnagConfiguration loadConfig];
// To prevent sending launch crashes synchronously;
config.sendLaunchCrashesSynchronously = NO;
[Bugsnag startWithConfiguration:config];
let config = BugsnagConfiguration.loadConfig()
// To prevent sending launch crashes synchronously;
config.sendLaunchCrashesSynchronously = false
Bugsnag.start(with: config)

Recovering after launch crashes

After a launch crash, it may be appropriate to take some actions in your app, such as removing cached data or resetting some persistent state, to make another one less likely to occur.

[Bugsnag start];

if (Bugsnag.lastRunInfo.crashedDuringLaunch) {
    // Enable "safe mode"
}
Bugsnag.start()

if Bugsnag.lastRunInfo?.crashedDuringLaunch == true {
    // Enable "safe mode"
}

The lastRunInfo object contains the following properties;

property type description
consecutiveLaunchCrashes Integer The number of consecutive runs that have ended with a crash while launching.
crashed Boolean true if the previous run crashed.
crashedDuringLaunch Boolean true if the previous run crashed while launching.