adds public method to handle user input from an alert view

This commit is contained in:
Lukas Spieß
2014-04-16 12:50:45 +02:00
parent 50b0eb9bd1
commit 9f9f44916a
2 changed files with 47 additions and 27 deletions

View File

@@ -247,6 +247,11 @@ typedef NS_ENUM(NSUInteger, BITCrashManagerUserInput) {
*/ */
@property (nonatomic, readonly) BOOL didCrashInLastSession; @property (nonatomic, readonly) BOOL didCrashInLastSession;
/**
Provides an interface to handle user input from a custom alert
@return BOOl if the input is a valid option
*/
- (BOOL)handleUserInput: (BITCrashManagerUserInput) userInput;
/** /**
Provides the time between startup and crash in seconds Provides the time between startup and crash in seconds

View File

@@ -487,6 +487,36 @@ NSString *const kBITCrashManagerStatus = @"BITCrashManagerStatus";
} }
} }
- (BOOL)handleUserInput:(BITCrashManagerUserInput)userInput {
switch (userInput) {
case BITCrashManagerUserInputDontSend:
if (self.delegate != nil && [self.delegate respondsToSelector:@selector(crashManagerWillCancelSendingCrashReport:)]) {
[self.delegate crashManagerWillCancelSendingCrashReport:self];
}
[self cleanCrashReports];
YES;
case BITCrashManagerUserInputSend:
[self sendCrashReports];
YES;
case BITCrashManagerUserInputAlwaysSend:
_crashManagerStatus = BITCrashManagerStatusAutoSend;
[[NSUserDefaults standardUserDefaults] setInteger:_crashManagerStatus forKey:kBITCrashManagerStatus];
[[NSUserDefaults standardUserDefaults] synchronize];
if (self.delegate != nil && [self.delegate respondsToSelector:@selector(crashManagerWillSendCrashReportsAlways:)]) {
[self.delegate crashManagerWillSendCrashReportsAlways:self];
}
[self sendCrashReports];
return YES;
default:
return NO;
}
}
#pragma mark - PLCrashReporter #pragma mark - PLCrashReporter
@@ -930,35 +960,20 @@ NSString *const kBITCrashManagerStatus = @"BITCrashManagerStatus";
#pragma mark - UIAlertView Delegate #pragma mark - UIAlertView Delegate
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex { - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
[self handleUserInput:buttonIndex]; switch (buttonIndex) {
case 0:
[self handleUserInput:BITCrashManagerUserInputDontSend];
break;
case 1:
[self handleUserInput:BITCrashManagerUserInputSend];
break;
case 2:
[self handleUserInput:BITCrashManagerUserInputAlwaysSend];
break;
}
} }
- (void)handleUserInput:(BITCrashManagerUserInput)userInput {
switch (userInput) {
case BITCrashManagerUserInputDontSend:
if (self.delegate != nil && [self.delegate respondsToSelector:@selector(crashManagerWillCancelSendingCrashReport:)]) {
[self.delegate crashManagerWillCancelSendingCrashReport:self];
}
_sendingInProgress = NO;
[self cleanCrashReports];
break;
case BITCrashManagerUserInputSend:
[self sendCrashReports];
break;
case BITCrashManagerUserInputAlwaysSend:
_crashManagerStatus = BITCrashManagerStatusAutoSend;
[[NSUserDefaults standardUserDefaults] setInteger:_crashManagerStatus forKey:kBITCrashManagerStatus];
[[NSUserDefaults standardUserDefaults] synchronize];
if (self.delegate != nil && [self.delegate respondsToSelector:@selector(crashManagerWillSendCrashReportsAlways:)]) {
[self.delegate crashManagerWillSendCrashReportsAlways:self];
}
[self sendCrashReports];
break;
}
}
#pragma mark - Networking #pragma mark - Networking