Add documentation for How to handle crashes on startup

This commit is contained in:
Andreas Linde 2012-08-04 16:20:55 +02:00
parent 01fea4fca2
commit e624fb71ab
2 changed files with 68 additions and 0 deletions

View File

@ -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 () <BITCrashManagerDelegate> {}
@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

View File

@ -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
===============