From 5de1034c898e4413ad478544fd4f8f5f45a75776 Mon Sep 17 00:00:00 2001 From: Axel Ogereau-Peltier <49279289+axel-op@users.noreply.github.com> Date: Wed, 8 Apr 2020 02:51:03 +0200 Subject: [PATCH] [crashlytics] Migration to new SDK: update Obj-C files --- .../Classes/FirebaseCrashlyticsPlugin.m | 42 +++++++------------ 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/packages/firebase_crashlytics/darwin/Classes/FirebaseCrashlyticsPlugin.m b/packages/firebase_crashlytics/darwin/Classes/FirebaseCrashlyticsPlugin.m index 607f4def8f02..279853b48aa0 100644 --- a/packages/firebase_crashlytics/darwin/Classes/FirebaseCrashlyticsPlugin.m +++ b/packages/firebase_crashlytics/darwin/Classes/FirebaseCrashlyticsPlugin.m @@ -18,7 +18,7 @@ + (void)registerWithRegistrar:(NSObject *)registrar { FirebaseCrashlyticsPlugin *instance = [[FirebaseCrashlyticsPlugin alloc] init]; [registrar addMethodCallDelegate:instance channel:channel]; - [Fabric with:@[ [Crashlytics self] ]]; + [FIRApp configure]; SEL sel = NSSelectorFromString(@"registerLibrary:withVersion:"); if ([FIRApp respondsToSelector:sel]) { @@ -41,29 +41,24 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result // Add logs. NSArray *logs = call.arguments[@"logs"]; for (NSString *log in logs) { - // Here and below, use CLSLog instead of CLS_LOG to try and avoid - // automatic inclusion of the current code location. It also ensures that - // the log is only written to Crashlytics and not also to the offline log - // as explained here: - // https://support.crashlytics.com/knowledgebase/articles/92519-how-do-i-use-logging - CLSLog(@"%@", log); + [[FIRCrashlytics crashlytics] logWithFormat:@"%@", log]; } // Set keys. NSArray *keys = call.arguments[@"keys"]; for (NSDictionary *key in keys) { if ([@"int" isEqualToString:key[@"type"]]) { - [[Crashlytics sharedInstance] setIntValue:(int)call.arguments[@"value"] - forKey:call.arguments[@"key"]]; + [[FIRCrashlytics crashlytics] setCustomValue:(int)call.arguments[@"value"] + forKey:call.arguments[@"key"]]; } else if ([@"double" isEqualToString:key[@"type"]]) { - [[Crashlytics sharedInstance] setFloatValue:[call.arguments[@"value"] floatValue] - forKey:call.arguments[@"key"]]; + [[FIRCrashlytics crashlytics] setCustomValue:[call.arguments[@"value"] floatValue] + forKey:call.arguments[@"key"]]; } else if ([@"string" isEqualToString:key[@"type"]]) { - [[Crashlytics sharedInstance] setObjectValue:call.arguments[@"value"] + [[FIRCrashlytics crashlytics] setCustomValue:call.arguments[@"value"] forKey:call.arguments[@"key"]]; } else if ([@"boolean" isEqualToString:key[@"type"]]) { - [[Crashlytics sharedInstance] setBoolValue:[call.arguments[@"value"] boolValue] - forKey:call.arguments[@"key"]]; + [[FIRCrashlytics crashlytics] setCustomValue:[call.arguments[@"value"] boolValue] + forKey:call.arguments[@"key"]]; } } @@ -71,7 +66,7 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result // Crashlytics. NSString *information = call.arguments[@"information"]; if ([information length] != 0) { - CLSLog(@"%@", information); + [[FIRCrashlytics crashlytics] logWithFormat:@"%@", information]; } // Report crash. @@ -87,22 +82,15 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result reason = [NSString stringWithFormat:@"thrown %@", context]; } - [[Crashlytics sharedInstance] recordCustomExceptionName:call.arguments[@"exception"] - reason:reason - frameArray:frames]; + // TODO: This is probably incorrect! + [[FIRCrashlytics crashlytics] recordError:call.arguments[@"exception"]] result(@"Error reported to Crashlytics."); } else if ([@"Crashlytics#isDebuggable" isEqualToString:call.method]) { - result([NSNumber numberWithBool:[Crashlytics sharedInstance].debugMode]); + result([NSNumber numberWithBool:[FIRCrashlytics crashlytics].debugMode]); } else if ([@"Crashlytics#getVersion" isEqualToString:call.method]) { - result([Crashlytics sharedInstance].version); - } else if ([@"Crashlytics#setUserEmail" isEqualToString:call.method]) { - [[Crashlytics sharedInstance] setUserEmail:call.arguments[@"email"]]; - result(nil); - } else if ([@"Crashlytics#setUserName" isEqualToString:call.method]) { - [[Crashlytics sharedInstance] setUserName:call.arguments[@"name"]]; - result(nil); + result([FIRCrashlytics crashlytics].version); } else if ([@"Crashlytics#setUserIdentifier" isEqualToString:call.method]) { - [[Crashlytics sharedInstance] setUserIdentifier:call.arguments[@"identifier"]]; + [[FIRCrashlytics crashlytics] setUserID:call.arguments[@"identifier"]]; result(nil); } else { result(FlutterMethodNotImplemented);