diff --git a/Sources/Raygun/RaygunClient.m b/Sources/Raygun/RaygunClient.m index 7243e3b..ebd1714 100644 --- a/Sources/Raygun/RaygunClient.m +++ b/Sources/Raygun/RaygunClient.m @@ -353,6 +353,42 @@ - (void)sendMessage:(RaygunMessage *)message { } } +- (BOOL)storeCrashReport:(RaygunMessage *)message { + if (message == nil) { + [RaygunLogger logWarning:@"Failed to store crash report - Message object cannot be nil"]; + return NO; + } + + // Call groupingKeyProvider if it's set + if (self.groupingKeyProvider != nil && message.details != nil) { + NSString *groupingKey = self.groupingKeyProvider(message.details); + + if (groupingKey != nil && ![groupingKey isEqualToString:@""]) { + message.details.groupingKey = groupingKey; + [RaygunLogger logDebug:@"Applied custom grouping key from provider: %@", groupingKey]; + } + } + + BOOL send = YES; + if (_beforeSendMessage != nil) { + send = _beforeSendMessage(message); + } + + if (!send) { + [RaygunLogger logDebug:@"Crash report was discarded by beforeSendMessage"]; + return NO; + } + + NSString *path = [_fileManager storeCrashReport:message withMaxReportsStored:self.maxReportsStoredOnDevice]; + if (path) { + [RaygunLogger logDebug:@"Stored crash report to %@", path]; + return YES; + } + + [RaygunLogger logError:@"Failed to store crash report to disk"]; + return NO; +} + - (NSError *)getInnerError:(NSError *)error { NSError *innerErrror = error.userInfo[NSUnderlyingErrorKey]; if (innerErrror) { diff --git a/Sources/public/RaygunClient.h b/Sources/public/RaygunClient.h index 3b1efca..1f5f6cb 100644 --- a/Sources/public/RaygunClient.h +++ b/Sources/public/RaygunClient.h @@ -181,6 +181,19 @@ NS_SWIFT_NAME(send(error:tags:customData:)); - (void)sendMessage:(RaygunMessage *)message NS_SWIFT_NAME(send(message:)); +/* + * Synchronously store a crash report to disk. + * The report will be sent to Raygun on the next app launch when enableCrashReporting is called. + * This is intended for use in contexts where the process is about to terminate (e.g. unhandled exception hooks) + * and asynchronous network requests would not complete. + * + * @param message The crash report to be stored + * + * @return YES if the report was successfully stored, NO otherwise. + */ +- (BOOL)storeCrashReport:(RaygunMessage *)message +NS_SWIFT_NAME(store(crashReport:)); + /* * Manually record a breadcrumb that will be included in the next crash report. *