diff --git a/docs/HowTo-Handle-Crashes-On-Startup-template.md b/docs/HowTo-Handle-Crashes-On-Startup-template.md new file mode 100644 index 0000000000..4c0bdd2a31 --- /dev/null +++ b/docs/HowTo-Handle-Crashes-On-Startup-template.md @@ -0,0 +1,67 @@ +Introduction +============ + +To catch and send crashes that occur while the app is starting up, the app has to get adjusted a little bit to make this work. + +The challenges in this scenario are: + +- Sending crash reports needs to be asynchronous, otherwise it would block the main thread or bad network conditions could make it even worse +- If the startup takes too long or the main thread is blocking too long, the watchdog process will kill the app +- The app might crash again before the crash report could have been send + + +HowTo +===== + +1. Setup the SDK +2. Check if the app crashed in the last session by checking `[BITCrashManager didCrashInLastSession]` +3. Check if `[BITCrashManager timeintervalCrashInLastSessionOccured]` is below a treshhold that you define. E.g. say your app usually requires 2 seconds for startup, and giving sending a crash report some time, you mighe choose `5` seconds as the treshhold +4. If the crash happened in that timeframe, delay your app initialization and show an intermediate screen +5. Implement the `BITCrashManagerDelegate` protocol methods `- (void)crashManager:(BITCrashManager *)crashManager didFailWithError:(NSError *)error;` and `- (void)crashManagerDidFinishSendingCrashReport:(BITCrashManager *)crashManager;` and continue app initialization + +Example +======= + + @interface BITAppDelegate () {} + @end + + + @implementation BITAppDelegate + + - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + [self.window makeKeyAndVisible]; + + [[BITHockeyManager sharedHockeyManager] configureWithIdentifier:@"<>" + delegate:nil]; + + // optionally enable logging to get more information about states. + [BITHockeyManager sharedHockeyManager].debugLogEnabled = YES; + + [[BITHockeyManager sharedHockeyManager] startManager]; + + if ([[BITHockeyManager.crashmanager] didCrashInLastSession] && + [[BITHockeyManager.crashmanager] timeintervalCrashInLastSessionOccured] < 5) { + // show intermediate UI + } else { + [self setupApplication]; + } + + return YES; + } + + - (void)setupApplication { + // setup your app specific code + } + + #pragma mark - BITCrashManagerDelegate + + - (void)crashManager:(BITCrashManager *)crashManager didFailWithError:(NSError *)error { + [self setupApplication]; + } + + - (void)crashManagerDidFinishSendingCrashReport:(BITCrashManager *)crashManager { + [self setupApplication]; + } + + @end + diff --git a/docs/index.md b/docs/index.md index 3f748ec3fc..c5ed0f167a 100644 --- a/docs/index.md +++ b/docs/index.md @@ -29,6 +29,7 @@ HowTos - [How to do app versioning](HowTo-App-Versioning) - [How to upload symbols for crash reporting](HowTo-Upload-Symbols) +- [How to handle crashes on startup](HowTo-Handle-Crashes-On-Startup) Troubleshooting ===============