Skip to content

Commit

Permalink
[crashlytics] Migration to new SDK: update Obj-C files
Browse files Browse the repository at this point in the history
  • Loading branch information
axel-op committed Apr 8, 2020
1 parent b22a659 commit 5de1034
Showing 1 changed file with 15 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)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]) {
Expand All @@ -41,37 +41,32 @@ - (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"]];
}
}

// Add additional information from the Flutter framework to the exception reported in
// Crashlytics.
NSString *information = call.arguments[@"information"];
if ([information length] != 0) {
CLSLog(@"%@", information);
[[FIRCrashlytics crashlytics] logWithFormat:@"%@", information];
}

// Report crash.
Expand All @@ -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);
Expand Down

0 comments on commit 5de1034

Please sign in to comment.