From f70474f74d1ccdc33bf689f0021a5ede45776368 Mon Sep 17 00:00:00 2001 From: warby613 Date: Tue, 2 Jun 2020 09:14:02 -0400 Subject: [PATCH] Prevent reconfiguration causing exception We ran into a problem with a configuration using both the firebasex and firebase-analytics plugins. The latter was doing "[FIRApp configure]" during the "[self application:application..." super call at the top of this function, which caused an exception when FIRApp was configured again by this plugin. The exception bypassed the remainder of the code block and prevented our app from receiving push notification data. --- src/ios/AppDelegate+FirebasePlugin.m | 36 ++++++++++++++-------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/ios/AppDelegate+FirebasePlugin.m b/src/ios/AppDelegate+FirebasePlugin.m index bf3d4d1c9..e669b7f5f 100644 --- a/src/ios/AppDelegate+FirebasePlugin.m +++ b/src/ios/AppDelegate+FirebasePlugin.m @@ -57,28 +57,28 @@ - (BOOL)application:(UIApplication *)application swizzledDidFinishLaunchingWithO @try{ instance = self; - // get GoogleService-Info.plist file path - NSString *filePath = [[NSBundle mainBundle] pathForResource:@"GoogleService-Info" ofType:@"plist"]; - - // if file is successfully found, use it - if(filePath){ - [FirebasePlugin.firebasePlugin _logMessage:@"GoogleService-Info.plist found, setup: [FIRApp configureWithOptions]"]; - // create firebase configure options passing .plist as content - FIROptions *options = [[FIROptions alloc] initWithContentsOfFile:filePath]; + if(![FIRApp defaultApp]) { + // get GoogleService-Info.plist file path + NSString *filePath = [[NSBundle mainBundle] pathForResource:@"GoogleService-Info" ofType:@"plist"]; - // configure FIRApp with options - [FIRApp configureWithOptions:options]; - if([FirebasePlugin.firebasePlugin _shouldEnableCrashlytics]){ - [Fabric with:@[[Crashlytics class]]]; + // if file is successfully found, use it + if(filePath){ + [FirebasePlugin.firebasePlugin _logMessage:@"GoogleService-Info.plist found, setup: [FIRApp configureWithOptions]"]; + // create firebase configure options passing .plist as content + FIROptions *options = [[FIROptions alloc] initWithContentsOfFile:filePath]; + + // configure FIRApp with options + [FIRApp configureWithOptions:options]; + if([FirebasePlugin.firebasePlugin _shouldEnableCrashlytics]){ + [Fabric with:@[[Crashlytics class]]]; + } + }else{ + // no .plist found, try default App + [FirebasePlugin.firebasePlugin _logError:@"GoogleService-Info.plist NOT FOUND, setup: [FIRApp defaultApp]"]; + [FIRApp configure]; } } - // no .plist found, try default App - if (![FIRApp defaultApp] && !filePath) { - [FirebasePlugin.firebasePlugin _logError:@"GoogleService-Info.plist NOT FOUND, setup: [FIRApp defaultApp]"]; - [FIRApp configure]; - } - shouldEstablishDirectChannel = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"shouldEstablishDirectChannel"] boolValue]; // Set FCM messaging delegate