From a1d7e0e84bfe44f4858587ed11f0bb51925b536e Mon Sep 17 00:00:00 2001 From: Themis wang Date: Tue, 3 Jan 2023 11:59:26 -0500 Subject: [PATCH] [Crashlytics fatals] Add iOS implementation --- crashlytics/src/IOSImpl.cs | 13 +++++++++---- .../Crashlytics_Platform.h | 1 + crashlytics/src/cpp/ios/CrashlyticsiOSWrapper.h | 2 +- crashlytics/src/cpp/ios/CrashlyticsiOSWrapper.m | 6 +++++- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/crashlytics/src/IOSImpl.cs b/crashlytics/src/IOSImpl.cs index 2144e635..05007d5a 100644 --- a/crashlytics/src/IOSImpl.cs +++ b/crashlytics/src/IOSImpl.cs @@ -60,7 +60,7 @@ internal class IOSImpl : Impl [DllImport("__Internal")] private static extern void CLURecordCustomException(string name, string reason, - Frame[] frames, int frameCount); + Frame[] frames, int frameCount, bool isOnDemand); [DllImport("__Internal")] private static extern bool CLUIsCrashlyticsCollectionEnabled(); @@ -96,7 +96,12 @@ public override void SetUserId(string identifier) public override void LogException(Exception exception) { var loggedException = LoggedException.FromException(exception); - RecordCustomException(loggedException); + RecordCustomException(loggedException, false); + } + + public override void LogExceptionAsFatal(Exception exception) { + var loggedException = LoggedException.FromException(exception); + RecordCustomException(loggedException, true); } public override bool IsCrashlyticsCollectionEnabled() { @@ -108,7 +113,7 @@ public override void SetCrashlyticsCollectionEnabled(bool enabled) { } // private void RecordCustomException(string name, string reason, string stackTraceString) - private void RecordCustomException(LoggedException loggedException) { + private void RecordCustomException(LoggedException loggedException, bool isOnDemand) { Dictionary[] parsedStackTrace = loggedException.ParsedStackTrace; List frames = new List(); @@ -121,7 +126,7 @@ private void RecordCustomException(LoggedException loggedException) { }); } - CLURecordCustomException(loggedException.Name, loggedException.Message, frames.ToArray(), frames.Count); + CLURecordCustomException(loggedException.Name, loggedException.Message, frames.ToArray(), frames.Count, isOnDemand); } } } diff --git a/crashlytics/src/cpp/ios/Crashlytics_PrivateHeaders/Crashlytics_Platform.h b/crashlytics/src/cpp/ios/Crashlytics_PrivateHeaders/Crashlytics_Platform.h index 09f394f4..b32d23cf 100644 --- a/crashlytics/src/cpp/ios/Crashlytics_PrivateHeaders/Crashlytics_Platform.h +++ b/crashlytics/src/cpp/ios/Crashlytics_PrivateHeaders/Crashlytics_Platform.h @@ -25,6 +25,7 @@ @property(nonatomic, strong, nullable) NSString* developmentPlatformName; @property(nonatomic, strong, nullable) NSString* developmentPlatformVersion; +- (void)recordOnDemandExceptionModel:(FIRExceptionModel* _Nonnull)exceptionModel; @end void FIRCLSUserLoggingRecordInternalKeyValue(NSString* key, id value); diff --git a/crashlytics/src/cpp/ios/CrashlyticsiOSWrapper.h b/crashlytics/src/cpp/ios/CrashlyticsiOSWrapper.h index 0903a3d9..57c18879 100644 --- a/crashlytics/src/cpp/ios/CrashlyticsiOSWrapper.h +++ b/crashlytics/src/cpp/ios/CrashlyticsiOSWrapper.h @@ -40,7 +40,7 @@ typedef struct Frame { // to used to log NSException objects. All safely-reportable NSExceptions are // automatically captured by Crashlytics. void CLURecordCustomException(const char *name, const char *reason, - Frame *frames, int frameCount); + Frame *frames, int frameCount, bool isOnDemand); // Returns true when the Crashlytics SDK is initialized. bool CLUIsInitialized(); diff --git a/crashlytics/src/cpp/ios/CrashlyticsiOSWrapper.m b/crashlytics/src/cpp/ios/CrashlyticsiOSWrapper.m index 15ec34a5..ff5ca2f3 100644 --- a/crashlytics/src/cpp/ios/CrashlyticsiOSWrapper.m +++ b/crashlytics/src/cpp/ios/CrashlyticsiOSWrapper.m @@ -38,7 +38,7 @@ - (BOOL)isCrashlyticsStarted; #pragma mark Main API -void CLURecordCustomException(const char *name, const char *reason, Frame *frames, int frameCount) { +void CLURecordCustomException(const char *name, const char *reason, Frame *frames, int frameCount, bool isOnDemand) { NSString *nameString = safeCharToNSString(name); NSString *reasonString = safeCharToNSString(reason); NSMutableArray *framesArray = [NSMutableArray arrayWithCapacity:frameCount]; @@ -57,6 +57,10 @@ void CLURecordCustomException(const char *name, const char *reason, Frame *frame [FIRExceptionModel exceptionModelWithName:nameString reason:reasonString]; model.stackTrace = framesArray; + if (isOnDemand) { + [[FIRCrashlytics crashlytics] recordOnDemandExceptionModel:model]; + return; + } [[FIRCrashlytics crashlytics] recordExceptionModel:model]; }