add DidSucceed and didFail callbacks
This commit is contained in:
Родитель
056300e1e5
Коммит
52c36b1625
|
@ -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
|
||||
|
|
|
@ -139,11 +139,13 @@
|
|||
SNMLogVerbose(@"INFO:Sending log %@", [container serializeLogWithPrettyPrinting:YES]);
|
||||
|
||||
// Notify delegates.
|
||||
for (id<SNMChannelDelegate> aDelegate in self.delegates) {
|
||||
[self enumerateDelgatesForSelector:@selector(channel:willSendLog:) withBlock:^(id<SNMChannelDelegate> delegate) {
|
||||
for (id<SNMLog> aLog in logArray) {
|
||||
[aDelegate channel:self willSendLog:aLog];
|
||||
[delegate channel:self willSendLog:aLog];
|
||||
}
|
||||
}
|
||||
}];
|
||||
|
||||
__block NSArray<SNMLog> *_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<SNMChannelDelegate> delegate) {
|
||||
for (id<SNMLog> aLog in logs) {
|
||||
[delegate channel:self didFailSendingLog:aLog withError:error];
|
||||
}
|
||||
}];
|
||||
}
|
||||
else {
|
||||
[self enumerateDelgatesForSelector:@selector(channel:didSucceedSendingLog:) withBlock:^(id<SNMChannelDelegate> delegate) {
|
||||
for (id<SNMLog> 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<SNMChannelDelegate> delegate))block {
|
||||
for (id<SNMChannelDelegate> delegate in self.delegates) {
|
||||
if (delegate && [delegate respondsToSelector:selector]) {
|
||||
block(delegate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#pragma mark - Timer
|
||||
|
||||
- (void)startTimer {
|
||||
|
|
|
@ -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<SNMChannel>)channel willSendLog:(id <SNMLog>)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<SNMChannel>)channel didSucceedSendingLog:(id <SNMLog>)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<SNMChannel>)channel didFailSendingLog:(id <SNMLog>)log withError:(NSError *)error;
|
||||
|
||||
|
||||
|
||||
@end
|
||||
|
|
|
@ -181,6 +181,24 @@ static void uncaught_cxx_exception_handler(const SNMCrashesUncaughtCXXExceptionI
|
|||
}
|
||||
}
|
||||
|
||||
- (void)channel:(id<SNMChannel>)channel didSucceedSendingLog:(id<SNMLog>)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<SNMChannel>)channel didFailSendingLog:(id<SNMLog>)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 {
|
||||
|
|
|
@ -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
|
||||
|
|
Загрузка…
Ссылка в новой задаче