diff --git a/README.md b/README.md index ca5879bc3..d5deed023 100644 --- a/README.md +++ b/README.md @@ -211,7 +211,16 @@ See [Specifying Android library versions](#specifying-android-library-versions) ### iOS only - `IOS_STRIP_DEBUG` - prevents symbolification of all libraries included via Cocoapods. See [Strip debug symbols](#strip-debug-symbols) for more info. -- `SETUP_RECAPTCHA_VERIFICATION` - automatically sets up reCAPTCHA verification for phone authentication on iOS. See [verifyPhoneNumber](#verifyphonenumber) for more info. + - e.g. `--variable IOS_STRIP_DEBUG=true` + - Defaults to `false` if not specified. +- `SETUP_RECAPTCHA_VERIFICATION` - automatically sets up reCAPTCHA verification for phone authentication on iOS. See [verifyPhoneNumber](#verifyphonenumber) for more info. + - e.g. `--variable IOS_STRIP_DEBUG=true` + - Defaults to `false` if not specified. +- `IOS_SHOULD_ESTABLISH_DIRECT_CHANNEL` - If `true` Firebase Messaging will automatically establish a socket-based, direct channel to the FCM server. + - e.g. `--variable IOS_SHOULD_ESTABLISH_DIRECT_CHANNEL=true` + - Defaults to `false` if not specified. + - See [`shouldEstablishDirectChannel`](https://firebase.google.com/docs/reference/ios/firebasemessaging/api/reference/Classes/FIRMessaging#/c:objc(cs)FIRMessaging(py)shouldEstablishDirectChannel) + - Note: Firebase Messaging iOS SDK version 7.0 will be a breaking change where the SDK will no longer support iOS Direct Channel API. ## Supported Cordova Versions - cordova: `>= 9` diff --git a/scripts/ios/helper.js b/scripts/ios/helper.js index 5b312b812..e4507cdf6 100755 --- a/scripts/ios/helper.js +++ b/scripts/ios/helper.js @@ -200,6 +200,10 @@ module.exports = { googlePlist["FIREBASE_CRASHLYTICS_COLLECTION_ENABLED"] = (pluginVariables['FIREBASE_CRASHLYTICS_COLLECTION_ENABLED'] !== "false" ? "true" : "false") ; googlePlistModified = true; } + if(typeof pluginVariables['IOS_SHOULD_ESTABLISH_DIRECT_CHANNEL'] !== 'undefined'){ + appPlist["shouldEstablishDirectChannel"] = (pluginVariables['IOS_SHOULD_ESTABLISH_DIRECT_CHANNEL'] === "true") ; + appPlistModified = true; + } if(pluginVariables['SETUP_RECAPTCHA_VERIFICATION'] === 'true'){ var reversedClientId = googlePlist['REVERSED_CLIENT_ID']; diff --git a/src/ios/AppDelegate+FirebasePlugin.m b/src/ios/AppDelegate+FirebasePlugin.m index 98d52701b..bf3d4d1c9 100644 --- a/src/ios/AppDelegate+FirebasePlugin.m +++ b/src/ios/AppDelegate+FirebasePlugin.m @@ -27,6 +27,7 @@ + (AppDelegate*) instance { static NSDictionary* mutableUserInfo; static FIRAuthStateDidChangeListenerHandle authStateChangeListener; static bool authStateChangeListenerInitialized = false; +static bool shouldEstablishDirectChannel = false; - (void)setDelegate:(id)delegate { objc_setAssociatedObject(self, kDelegateKey, delegate, OBJC_ASSOCIATION_RETAIN_NONATOMIC); @@ -77,10 +78,12 @@ - (BOOL)application:(UIApplication *)application swizzledDidFinishLaunchingWithO [FirebasePlugin.firebasePlugin _logError:@"GoogleService-Info.plist NOT FOUND, setup: [FIRApp defaultApp]"]; [FIRApp configure]; } + + shouldEstablishDirectChannel = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"shouldEstablishDirectChannel"] boolValue]; // Set FCM messaging delegate [FIRMessaging messaging].delegate = self; - [FIRMessaging messaging].shouldEstablishDirectChannel = true; + [FIRMessaging messaging].shouldEstablishDirectChannel = shouldEstablishDirectChannel; // Setup Firestore [FirebasePlugin setFirestore:[FIRFirestore firestore]]; @@ -119,15 +122,15 @@ - (BOOL)application:(UIApplication *)application swizzledDidFinishLaunchingWithO } - (void)applicationDidBecomeActive:(UIApplication *)application { - [FIRMessaging messaging].shouldEstablishDirectChannel = true; self.applicationInBackground = @(NO); - [FirebasePlugin.firebasePlugin _logMessage:@"FCM direct channel = true"]; + [FIRMessaging messaging].shouldEstablishDirectChannel = shouldEstablishDirectChannel; + [FirebasePlugin.firebasePlugin _logMessage:[NSString stringWithFormat:@"Enter foreground: FCM direct channel = %@", shouldEstablishDirectChannel ? @"true" : @"false"]]; } - (void)applicationDidEnterBackground:(UIApplication *)application { - [FIRMessaging messaging].shouldEstablishDirectChannel = false; self.applicationInBackground = @(YES); - [FirebasePlugin.firebasePlugin _logMessage:@"FCM direct channel = false"]; + [FIRMessaging messaging].shouldEstablishDirectChannel = false; + [FirebasePlugin.firebasePlugin _logMessage:@"Enter background: FCM direct channel = false"]; } # pragma mark - Google SignIn