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; NSURLConnection *_urlConnection;
BOOL _sendingInProgress; BOOL _sendingInProgress;
BOOL _isSetup;
} }

View File

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