diff --git a/Puppet/Puppet/AppDelegate.m b/Puppet/Puppet/AppDelegate.m index 1a732f996..e37716aa8 100644 --- a/Puppet/Puppet/AppDelegate.m +++ b/Puppet/Puppet/AppDelegate.m @@ -69,4 +69,14 @@ SNMLogVerbose(@"Will send error report with: %@", errorReport.exceptionReason); } +- (void)crashes:(SNMCrashes *)crashes didSucceedSendingErrorReport:(SNMErrorReport *)errorReport { + SNMLogVerbose(@"Did succeed error report sending with: %@", errorReport.exceptionReason); + +} + +- (void)crashes:(SNMCrashes *)crashes didFailSendingErrorReport:(SNMErrorReport *)errorReport withError:(NSError *)error { + SNMLogVerbose(@"Did fail sending report with: %@, and error %@", errorReport.exceptionReason, error.localizedDescription); + +} + @end diff --git a/SonomaCore/SonomaCore/Internals/Channel/SNMChannelDefault.m b/SonomaCore/SonomaCore/Internals/Channel/SNMChannelDefault.m index c239c9236..a702a3a35 100644 --- a/SonomaCore/SonomaCore/Internals/Channel/SNMChannelDefault.m +++ b/SonomaCore/SonomaCore/Internals/Channel/SNMChannelDefault.m @@ -139,11 +139,13 @@ SNMLogVerbose(@"INFO:Sending log %@", [container serializeLogWithPrettyPrinting:YES]); // Notify delegates. - for (id aDelegate in self.delegates) { + [self enumerateDelgatesForSelector:@selector(channel:willSendLog:) withBlock:^(id delegate) { for (id aLog in logArray) { - [aDelegate channel:self willSendLog:aLog]; + [delegate channel:self willSendLog:aLog]; } - } + }]; + + __block NSArray *_Nullable logs = [logArray copy]; // Forward logs to the sender. [self.sender sendAsync:container @@ -153,6 +155,21 @@ @"status code:%lu", (unsigned long)statusCode); + if(statusCode != 200) { + [self enumerateDelgatesForSelector:@selector(channel:didFailSendingLog:withError:) withBlock:^(id delegate) { + for (id aLog in logs) { + [delegate channel:self didFailSendingLog:aLog withError:error]; + } + }]; + } + else { + [self enumerateDelgatesForSelector:@selector(channel:didSucceedSendingLog:) withBlock:^(id delegate) { + for (id aLog in logs) { + [delegate channel:self didSucceedSendingLog:aLog]; + } + }]; + } + // Remove from pending logs and storage. [self.pendingBatchIds removeObject:batchId]; [self.storage deleteLogsForId:batchId withStorageKey:self.configuration.name]; @@ -175,6 +192,15 @@ } } +- (void)enumerateDelgatesForSelector:(SEL)selector withBlock:(void (^)(id delegate))block { + for (id delegate in self.delegates) { + if (delegate && [delegate respondsToSelector:selector]) { + block(delegate); + } + } +} + + #pragma mark - Timer - (void)startTimer { diff --git a/SonomaCore/SonomaCore/Internals/Channel/SNMChannelDelegate.h b/SonomaCore/SonomaCore/Internals/Channel/SNMChannelDelegate.h index da875f6b6..52da8ee8f 100644 --- a/SonomaCore/SonomaCore/Internals/Channel/SNMChannelDelegate.h +++ b/SonomaCore/SonomaCore/Internals/Channel/SNMChannelDelegate.h @@ -14,10 +14,27 @@ /** * Callback method that will be called before each log will be send to the - * server. - * @param Instance of SNMChannel. + * server. * @param Instance of SNMChannel. * @param log The log to be sent. */ - (void)channel:(id)channel willSendLog:(id )log; +/** + * Callback method that will be called in case the SDK was able to send a log. + * @param Instance of SNMChannel. + * @param log The log to be sent. + * @param error The error that occured. + */ +- (void)channel:(id)channel didSucceedSendingLog:(id )log; + +/** + * Callback method that will be called in case the SDK was unable to send a log. + * @param Instance of SNMChannel. + * @param log The log to be sent. + * @param error The error that occured. + */ +- (void)channel:(id)channel didFailSendingLog:(id )log withError:(NSError *)error; + + + @end diff --git a/SonomaCrashes/SonomaCrashes/SNMCrashes.m b/SonomaCrashes/SonomaCrashes/SNMCrashes.m index 24698ae08..98de01a3a 100644 --- a/SonomaCrashes/SonomaCrashes/SNMCrashes.m +++ b/SonomaCrashes/SonomaCrashes/SNMCrashes.m @@ -181,6 +181,24 @@ static void uncaught_cxx_exception_handler(const SNMCrashesUncaughtCXXExceptionI } } +- (void)channel:(id)channel didSucceedSendingLog:(id)log { + if(self.delegate) { + if ([((NSObject *)log) isKindOfClass:[SNMAppleErrorLog class]]) { + SNMErrorReport *report = [SNMErrorLogFormatter errorReportFromLog:((SNMAppleErrorLog*)log)]; + [self.delegate crashes:self didSucceedSendingErrorReport:report]; + } + } +} + +- (void)channel:(id)channel didFailSendingLog:(id)log withError:(NSError *)error { + if(self.delegate) { + if ([((NSObject *)log) isKindOfClass:[SNMAppleErrorLog class]]) { + SNMErrorReport *report = [SNMErrorLogFormatter errorReportFromLog:((SNMAppleErrorLog*)log)]; + [self.delegate crashes:self didFailSendingErrorReport:report withError:error]; + } + } +} + #pragma mark - Crash reporter configuration - (void)configureCrashReporter { diff --git a/SonomaCrashes/SonomaCrashes/SNMCrashesDelegate.h b/SonomaCrashes/SonomaCrashes/SNMCrashesDelegate.h index 47f9327df..478b18a44 100644 --- a/SonomaCrashes/SonomaCrashes/SNMCrashesDelegate.h +++ b/SonomaCrashes/SonomaCrashes/SNMCrashesDelegate.h @@ -13,9 +13,25 @@ /** * Callback method that will be called before each error will be send to the - * server. - * @param instance of SNMCrashes. + * server. Use this callback to display custom UI while crashes are sent to the server. + * @param crashes The instance of SNMCrashes. + * @param errorReport The errorReport that will be sent. */ - (void)crashes:(SNMCrashes *)crashes willSendErrorReport:(SNMErrorReport *)errorReport; +/** + * Callback method that will be called in case the SDK was unable to send an error report to the server. Use this method to hide custom + * @param crashes The instance of SNMCrashes. + * @param errorReport The errorReport that Sonoma sent. + */ +- (void) crashes:(SNMCrashes*)crashes didSucceedSendingErrorReport:(SNMErrorReport*) errorReport; + +/** + * Callback method that will be called in case the SDK was unable to send an error report to the server. + * @param crashes The instance of SNMCrashes. + * @param errorReport The errorReport that Sonoma tried to send. + * @param error The error that occured. + */ +- (void) crashes:(SNMCrashes*)crashes didFailSendingErrorReport:(SNMErrorReport*) errorReport withError:(NSError *) error; + @end