Make sure PLCrashReporter only gets initialized once, even on manually invoking the method multiple times

And also catch the exception PLCrashReporter throws, if the develop is somehow trying to initialize it multiple times.
This commit is contained in:
Andreas Linde 2012-08-14 12:16:53 +02:00
parent 40041ad882
commit ece5f8bc49
2 changed files with 24 additions and 11 deletions

View File

@ -93,6 +93,7 @@ static NSString *kBITCrashManagerStatus = @"BITCrashManagerStatus";
NSURLConnection *_urlConnection;
BOOL _sendingInProgress;
BOOL _isSetup;
}

View File

@ -75,6 +75,7 @@
_delegate = nil;
_showAlwaysButton = NO;
_isSetup = NO;
_crashIdenticalCurrentVersion = YES;
_urlConnection = nil;
@ -422,18 +423,29 @@
- (void)startManager {
if (_crashManagerStatus == BITCrashManagerStatusDisabled) return;
PLCrashReporter *crashReporter = [PLCrashReporter sharedReporter];
NSError *error = NULL;
// Check if we previously crashed
if ([crashReporter hasPendingCrashReport]) {
_didCrashInLastSession = YES;
[self handleCrashReport];
if (!_isSetup) {
PLCrashReporter *crashReporter = [PLCrashReporter sharedReporter];
NSError *error = NULL;
// Check if we previously crashed
if ([crashReporter hasPendingCrashReport]) {
_didCrashInLastSession = YES;
[self handleCrashReport];
}
// PLCrashReporter is throwing an NSException if it is being enabled again
// even though it already is enabled
@try {
// Enable the Crash Reporter
if (![crashReporter enableCrashReporterAndReturnError: &error])
NSLog(@"WARNING: Could not enable crash reporter: %@", [error localizedDescription]);
}
@catch (NSException * e) {
NSLog(@"WARNING: %@", [e reason]);
}
_isSetup = NO;
}
// Enable the Crash Reporter
if (![crashReporter enableCrashReporterAndReturnError: &error])
NSLog(@"WARNING: Could not enable crash reporter: %@", [error localizedDescription]);
[self performSelector:@selector(invokeDelayedProcessing) withObject:nil afterDelay:0.5];
}