Fix handling of some edge cases in relation to sending approved crash reports

This commit is contained in:
Andreas Linde 2014-06-10 15:37:13 +02:00
parent 05e0e7ccd6
commit 12682d9e3d
2 changed files with 21 additions and 10 deletions

View File

@ -839,20 +839,22 @@ static PLCrashReporterCallbacks plCrashCallbacks = {
} }
/** /**
* Check if there are any crash reports available which the user did not approve yet Get the filename of the first not approved crash report
*
* @return `YES` if there are crash reports pending that are not approved, `NO` otherwise @return NSString Filename of the first found not approved crash report
*/ */
- (BOOL)hasNonApprovedCrashReports { - (NSString *)firstNotApprovedCrashReport {
if ((!_approvedCrashReports || [_approvedCrashReports count] == 0) && [_crashFiles count] > 0) return YES; if ((!_approvedCrashReports || [_approvedCrashReports count] == 0) && [_crashFiles count] > 0) {
return [_crashFiles objectAtIndex:0];
}
for (NSUInteger i=0; i < [_crashFiles count]; i++) { for (NSUInteger i=0; i < [_crashFiles count]; i++) {
NSString *filename = [_crashFiles objectAtIndex:i]; NSString *filename = [_crashFiles objectAtIndex:i];
if (![_approvedCrashReports objectForKey:filename]) return YES; if (![_approvedCrashReports objectForKey:filename]) return filename;
} }
return NO; return nil;
} }
/** /**
@ -935,9 +937,17 @@ static PLCrashReporterCallbacks plCrashCallbacks = {
if (!_sendingInProgress && [self hasPendingCrashReport]) { if (!_sendingInProgress && [self hasPendingCrashReport]) {
_sendingInProgress = YES; _sendingInProgress = YES;
NSString *notApprovedReportFilename = [self firstNotApprovedCrashReport];
// this can happen in case there is a non approved crash report but it didn't happen in the previous app session
if (notApprovedReportFilename && !_lastCrashFilename) {
_lastCrashFilename = [notApprovedReportFilename lastPathComponent];
}
if (!BITHockeyBundle()) { if (!BITHockeyBundle()) {
[self sendNextCrashReport]; [self sendNextCrashReport];
} else if (_crashManagerStatus != BITCrashManagerStatusAutoSend && [self hasNonApprovedCrashReports]) { } else if (_crashManagerStatus != BITCrashManagerStatusAutoSend && notApprovedReportFilename) {
if (self.delegate != nil && [self.delegate respondsToSelector:@selector(crashManagerWillShowSubmitCrashReportAlert:)]) { if (self.delegate != nil && [self.delegate respondsToSelector:@selector(crashManagerWillShowSubmitCrashReportAlert:)]) {
[self.delegate crashManagerWillShowSubmitCrashReportAlert:self]; [self.delegate crashManagerWillShowSubmitCrashReportAlert:self];
@ -1336,14 +1346,14 @@ static PLCrashReporterCallbacks plCrashCallbacks = {
// store this crash report as user approved, so if it fails it will retry automatically // store this crash report as user approved, so if it fails it will retry automatically
[_approvedCrashReports setObject:[NSNumber numberWithBool:YES] forKey:filename]; [_approvedCrashReports setObject:[NSNumber numberWithBool:YES] forKey:filename];
[self saveSettings];
BITHockeyLog(@"INFO: Sending crash reports:\n%@", crashXML); BITHockeyLog(@"INFO: Sending crash reports:\n%@", crashXML);
[self sendCrashReportWithFilename:filename xml:crashXML attachment:attachment]; [self sendCrashReportWithFilename:filename xml:crashXML attachment:attachment];
} else { } else {
// we cannot do anything with this report, so delete it // we cannot do anything with this report, so delete it
[self cleanCrashReportWithFilename:filename]; [self cleanCrashReportWithFilename:filename];
} }
[self saveSettings];
} }

View File

@ -65,6 +65,7 @@
if (![[NSThread currentThread] isMainThread]) { if (![[NSThread currentThread] isMainThread]) {
[self performSelector:@selector(start) onThread:NSThread.mainThread withObject:nil waitUntilDone:NO]; [self performSelector:@selector(start) onThread:NSThread.mainThread withObject:nil waitUntilDone:NO];
return;
} }
if(self.isCancelled) { if(self.isCancelled) {