Skip to content

Commit

Permalink
(iOS): Set shouldEstablishDirectChannel via a plugin variable which d…
Browse files Browse the repository at this point in the history
…efaults to false. Resolves #406.
  • Loading branch information
Dave Alden committed May 22, 2020
1 parent 524b70b commit fa6c286
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
4 changes: 4 additions & 0 deletions scripts/ios/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'];

Expand Down
13 changes: 8 additions & 5 deletions src/ios/AppDelegate+FirebasePlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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]];
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fa6c286

Please sign in to comment.