From ece5f8bc4998b278d105cf72f2093b995bda6d30 Mon Sep 17 00:00:00 2001 From: Andreas Linde Date: Tue, 14 Aug 2012 12:16:53 +0200 Subject: [PATCH] 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. --- Classes/BITCrashManager.h | 1 + Classes/BITCrashManager.m | 34 +++++++++++++++++++++++----------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/Classes/BITCrashManager.h b/Classes/BITCrashManager.h index 4edbfe6dd6..ca40c43e57 100644 --- a/Classes/BITCrashManager.h +++ b/Classes/BITCrashManager.h @@ -93,6 +93,7 @@ static NSString *kBITCrashManagerStatus = @"BITCrashManagerStatus"; NSURLConnection *_urlConnection; BOOL _sendingInProgress; + BOOL _isSetup; } diff --git a/Classes/BITCrashManager.m b/Classes/BITCrashManager.m index 75baa7f4b4..6ac77ebfc9 100644 --- a/Classes/BITCrashManager.m +++ b/Classes/BITCrashManager.m @@ -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]; }