Provide a delegate method to disable crash reporting instead of using a property

This commit is contained in:
Andreas Linde 2012-07-22 21:42:28 +02:00
parent 141d9e5890
commit 93bd10ced5
3 changed files with 24 additions and 10 deletions

View File

@ -95,7 +95,7 @@ typedef enum BITCrashStatus {
NSFileManager *_fileManager;
BOOL _crashIdenticalCurrentVersion;
BOOL _crashReportActivated;
BOOL _crashReportDisabled;
NSMutableArray *_crashFiles;

View File

@ -99,16 +99,12 @@
_analyzerStarted = 0;
}
testValue = nil;
testValue = [[NSUserDefaults standardUserDefaults] stringForKey:kBITCrashActivated];
if (testValue) {
_crashReportActivated = [[NSUserDefaults standardUserDefaults] boolForKey:kBITCrashActivated];
} else {
_crashReportActivated = YES;
[[NSUserDefaults standardUserDefaults] setValue:[NSNumber numberWithBool:YES] forKey:kBITCrashActivated];
_crashReportDisabled = NO;
if (self.delegate != nil && [self.delegate respondsToSelector:@selector(shouldDisableCrashManager:)]) {
_crashReportDisabled = [self.delegate shouldDisableCrashManager:self];
}
if (_crashReportActivated) {
if (!_crashReportDisabled) {
_crashFiles = [[NSMutableArray alloc] init];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
_crashesDir = [[NSString stringWithFormat:@"%@", [[paths objectAtIndex:0] stringByAppendingPathComponent:@"/crashes/"]] retain];
@ -295,7 +291,7 @@
}
- (BOOL)hasPendingCrashReport {
if (_crashReportActivated) {
if (!_crashReportDisabled) {
if ([_crashFiles count] == 0 && [self.fileManager fileExistsAtPath:_crashesDir]) {
NSString *file = nil;
NSError *error = NULL;

View File

@ -37,6 +37,24 @@
@optional
///-----------------------------------------------------------------------------
/// @name Configuration
///-----------------------------------------------------------------------------
/** Return YES if you the crash reporting module should be disabled
The crash reporting module is enabled by default. Implement this delegate and
return NO if you want to disable it.
If you intend to implement a user setting to let them enable or disable
crash reporting, this delegate should be used to return that value.
@param crashManager The `BITCrashManager` instance invoking this delegate
*/
- (BOOL)shouldDisableCrashManager:(BITCrashManager *)crashManager;
///-----------------------------------------------------------------------------
/// @name Additional meta data
///-----------------------------------------------------------------------------