From 1f4161bff6763b3ad2598b99d84d2aaad46c477e Mon Sep 17 00:00:00 2001 From: Mark Date: Sun, 17 Nov 2019 14:49:04 +1100 Subject: [PATCH 01/17] createChannel suggestion for multiple sounds --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index a79594c54..6bb40ba59 100644 --- a/README.md +++ b/README.md @@ -1307,6 +1307,29 @@ Example FCM v1 API notification message payload for invoking the above example c ``` +If your Android app plays multiple sounds or effects, it's a good idea to create a channel for each likely combination. This is because once a channel is created you cannot override sounds/effects. +IE, expanding on the createChannel example: +```javascript +let soundList = ["train","woop","clock","radar","sonar"]; +for (let key of soundList) { + let name = "yourchannelprefix_" + key; + channel.id = name; + channel.sound = key; + channel.name = "Your description " + key; + + // Create the channel + window.FirebasePlugin.createChannel(channel, + function(){ + console.log('Notification Channel created: ' + channel.id + " " + JSON.stringify(channel)); + }, + function(error){ + console.log('Create notification channel error: ' + error); + }); +} +``` + +Note, if you just have one sound / effect combination that the user can customise, just use setDefaultChannel when any changes are made. + #### setDefaultChannel Android 8+ only. Overrides the properties for the default channel. From 5d497b312dd16be29aa1ec19b21d5cb6872ab9e3 Mon Sep 17 00:00:00 2001 From: Dave Alden Date: Mon, 16 Mar 2020 08:27:11 +0000 Subject: [PATCH 02/17] (Android): Don't display app icon for large notification icon on Android. Resolves #343. --- CHANGELOG.md | 2 ++ .../FirebasePluginMessagingService.java | 19 +++++++++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc8b41ba1..168f3bcd2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +* (Android): Don't display app icon for large notification icon on Android. Resolves [#343](https://github.com/dpa99c/cordova-plugin-firebasex/issues/343). + # Version 9.0.1 * Re-add Firebase Inapp Messaging SDK component to master branch. * Document `cli_build` branch. See [#326](https://github.com/dpa99c/cordova-plugin-firebasex/issues/326). diff --git a/src/android/FirebasePluginMessagingService.java b/src/android/FirebasePluginMessagingService.java index 7fa7ffc8b..3f385d94f 100755 --- a/src/android/FirebasePluginMessagingService.java +++ b/src/android/FirebasePluginMessagingService.java @@ -287,17 +287,16 @@ private void sendMessage(RemoteMessage remoteMessage, Map data, } int largeIconResID; - if (customLargeIconResID != 0) { - largeIconResID = customLargeIconResID; - Log.d(TAG, "Large icon: custom="+icon); - }else if (defaultLargeIconResID != 0) { - Log.d(TAG, "Large icon: default="+defaultLargeIconName); - largeIconResID = defaultLargeIconResID; - } else { - Log.d(TAG, "Large icon: application"); - largeIconResID = getApplicationInfo().icon; + if (customLargeIconResID != 0 || defaultLargeIconResID != 0) { + if (customLargeIconResID != 0) { + largeIconResID = customLargeIconResID; + Log.d(TAG, "Large icon: custom="+icon); + }else{ + Log.d(TAG, "Large icon: default="+defaultLargeIconName); + largeIconResID = defaultLargeIconResID; + } + notificationBuilder.setLargeIcon(BitmapFactory.decodeResource(getApplicationContext().getResources(), largeIconResID)); } - notificationBuilder.setLargeIcon(BitmapFactory.decodeResource(getApplicationContext().getResources(), largeIconResID)); } // Color From 8d9b391eecdb102cce286fb49c23b46f30a9e8ee Mon Sep 17 00:00:00 2001 From: Dave Alden Date: Wed, 18 Mar 2020 11:57:50 +0000 Subject: [PATCH 03/17] (Documentation) Clarify use of notification channels on Android 8+ vs message payload key on Android <=7 for setting custom notification sound. --- README.md | 110 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 98 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 1293b13dc..90c9c4c77 100644 --- a/README.md +++ b/README.md @@ -51,12 +51,15 @@ To help ensure this plugin is kept updated, new features are added and bugfixes - [Android background notifications](#android-background-notifications) - [Android foreground notifications](#android-foreground-notifications) - [Android Notification Channels](#android-notification-channels) + - [Android 7 and below](#android-7-and-below) - [Android Notification Icons](#android-notification-icons) - [Android Default Notification Icon](#android-default-notification-icon) - [Android Large Notification Icon](#android-large-notification-icon) - [Android Custom Notification Icons](#android-custom-notification-icons) - [Android Notification Color](#android-notification-color) - [Android Notification Sound](#android-notification-sound) + - [Android 8.0 and above](#android-80-and-above) + - [On Android 7 and below](#on-android-7-and-below) - [iOS notifications](#ios-notifications) - [iOS background notifications](#ios-background-notifications) - [iOS notification sound](#ios-notification-sound) @@ -608,28 +611,55 @@ However, if you set the `notification_foreground` key in the `data` section of t ### Android Notification Channels - Android 8 (O) introduced [notification channels](https://developer.android.com/training/notify-user/channels). -- Notification channels are configured by the app and used to determine the sound/lights/vibration settings of system notifications. -- By default, this plugin creates a default channel with [default properties]((#default-android-channel-properties) +- Notification channels are configured by the app and used to determine the **sound/lights/vibration** settings of system notifications. +- By default, this plugin creates a default channel with [default properties](#default-android-channel-properties) - These can be overridden via the [setDefaultChannel](#setdefaultchannel) function. -- The plugin enables the creation of additional custom channels via the [createChannel](#createchannel) function. +- The plugin enables the creation of additional custom channels via the [createChannel](#createchannel) function. -On Android 7 and below, the sound setting of system notifications is specified in the notification message itself, for example: +First you need to create a custom channel with the desired settings, for example: + +```javascript +var channel = { + id: "my_channel_id", + sound: "mysound", + vibration: true, + light: true, + lightColor: parseInt("FF0000FF", 16).toString(), + importance: 4, + badge: true, + visibility: 1 +}; + +FirebasePlugin.createChannel(channel, +function(){ + console.log('Channel created: ' + channel.id); +}, +function(error){ + console.log('Create channel error: ' + error); +}); +``` + +Then reference it from your message payload: ```json { "name": "my_notification", - "notification": { - "body": "Notification body", - "title": "Notification title" - }, + "notification": { + "body": "Notification body", + "title": "Notification title" + }, "android": { "notification": { - "sound": "my_sound", - "tag": "default" + "channel_id": "my_channel_id" + } } } ``` +#### Android 7 and below +- the channel referenced in the message payload will be ignored +- the sound setting of system notifications is specified in the notification message itself - see [Android Notification Sound](#android-notification-sound). + ### Android Notification Icons By default the plugin will use the default app icon for notification messages. @@ -792,7 +822,63 @@ To do this, you can add `` tags to your `config.xml` to deploy th ``` -In a notification message, you specify the sound file name in the `android.notification` section, for example: +To ensure your custom sounds works on all versions of Android, be sure to include both the channel name and sound name in your message payload (see below for details), for example: + +```json +{ + "name": "my_notification", + "notification": { + "body": "Notification body", + "title": "Notification title" + }, + "android": { + "notification": { + "channel_id": "my_channel_id", + "sound": "my_sound" + } + } +} +``` + +#### Android 8.0 and above +On Android 8.0 and above, the notification sound is specified by which [Android notification channel](#android-notification-channels) is referenced in the notification message payload. +First create a channel that references your sound, for example: + +```javascript +var channel = { + id: "my_channel_id", + sound: "my_sound" +}; + +FirebasePlugin.createChannel(channel, +function(){ + console.log('Channel created: ' + channel.id); +}, +function(error){ + console.log('Create channel error: ' + error); +}); +``` + +Then reference that channel in your message payload: + +```json +{ + "name": "my_notification", + "notification": { + "body": "Notification body", + "title": "Notification title" + }, + "android": { + "notification": { + "channel_id": "my_channel_id" + } + } +} +``` + +#### On Android 7 and below +On Android 7 and below, you need to specify the sound file name in the `android.notification` section of the message payload. +For example: ```json { @@ -822,7 +908,7 @@ And in a data message by specifying it in the `data` section: } } ``` - + - To play the default notification sound, set `"sound": "default"`. - To display a silent notification (no sound), omit the `sound` key from the message. From 4af9eb4f5efc437bf906ac33998b20cbfa9dbea5 Mon Sep 17 00:00:00 2001 From: Tim Brust Date: Wed, 25 Mar 2020 14:48:16 +0000 Subject: [PATCH 04/17] docs: fix broken markdown link for strip debug symbols --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 90c9c4c77..b4e8c0253 100644 --- a/README.md +++ b/README.md @@ -427,7 +427,7 @@ If your iOS app build contains too many debug symbols (i.e. because you include ITMS-90381: Too many symbol files - These symbols have no corresponding slice in any binary [16EBC8AC-DAA9-39CF-89EA-6A58EB5A5A2F.symbols, 1B105D69-2039-36A4-A04D-96C1C5BAF235.symbols, 476EACDF-583B-3B29-95B9-253CB41097C8.symbols, 9789B03B-6774-3BC9-A8F0-B9D44B08DCCB.symbols, 983BAE60-D245-3291-9F9C-D25E610846AC.symbols]. -To prevent this, you can set the `IOS_STRIP_DEBUG` plugin variable which prevents symbolification of all libraries included via Cocoapods (see here)[https://stackoverflow.com/a/48518656/777265]: +To prevent this, you can set the `IOS_STRIP_DEBUG` plugin variable which prevents symbolification of all libraries included via Cocoapods [see here](https://stackoverflow.com/a/48518656/777265): cordova plugin add cordova-plugin-firebasex --variable IOS_STRIP_DEBUG=true From 4a6a01444c2265ddf7b5264024c7c323fc0db3cb Mon Sep 17 00:00:00 2001 From: Tim Brust Date: Wed, 25 Mar 2020 14:51:29 +0000 Subject: [PATCH 05/17] docs: adds quotes around more information --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b4e8c0253..c3099490d 100644 --- a/README.md +++ b/README.md @@ -427,7 +427,7 @@ If your iOS app build contains too many debug symbols (i.e. because you include ITMS-90381: Too many symbol files - These symbols have no corresponding slice in any binary [16EBC8AC-DAA9-39CF-89EA-6A58EB5A5A2F.symbols, 1B105D69-2039-36A4-A04D-96C1C5BAF235.symbols, 476EACDF-583B-3B29-95B9-253CB41097C8.symbols, 9789B03B-6774-3BC9-A8F0-B9D44B08DCCB.symbols, 983BAE60-D245-3291-9F9C-D25E610846AC.symbols]. -To prevent this, you can set the `IOS_STRIP_DEBUG` plugin variable which prevents symbolification of all libraries included via Cocoapods [see here](https://stackoverflow.com/a/48518656/777265): +To prevent this, you can set the `IOS_STRIP_DEBUG` plugin variable which prevents symbolification of all libraries included via Cocoapods ([see here for more information](https://stackoverflow.com/a/48518656/777265)): cordova plugin add cordova-plugin-firebasex --variable IOS_STRIP_DEBUG=true From 1f2fbc9db9f4a7fb62190097e469a82b1c8c7a68 Mon Sep 17 00:00:00 2001 From: Dave Alden Date: Fri, 3 Apr 2020 17:00:59 +0100 Subject: [PATCH 06/17] [Android] Try to sign out of Google when signing out of Firebase. Addresses #353. --- src/android/FirebasePlugin.java | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/android/FirebasePlugin.java b/src/android/FirebasePlugin.java index d5c89e18f..283ea7d7b 100755 --- a/src/android/FirebasePlugin.java +++ b/src/android/FirebasePlugin.java @@ -23,12 +23,14 @@ import com.crashlytics.android.Crashlytics; +import com.google.android.gms.auth.api.Auth; import com.google.android.gms.auth.api.signin.GoogleSignIn; import com.google.android.gms.auth.api.signin.GoogleSignInAccount; import com.google.android.gms.auth.api.signin.GoogleSignInClient; import com.google.android.gms.auth.api.signin.GoogleSignInOptions; import com.google.android.gms.common.api.ApiException; import com.google.android.gms.common.api.CommonStatusCodes; +import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.tasks.OnCompleteListener; import com.google.android.gms.tasks.OnFailureListener; import com.google.android.gms.tasks.OnSuccessListener; @@ -1006,8 +1008,24 @@ public void run() { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, "No user is currently signed")); return; } + // Sign out of Firebase FirebaseAuth.getInstance().signOut(); - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK)); + + // Try to sign out of Google + try{ + GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).build(); + GoogleSignInClient mGoogleSignInClient = GoogleSignIn.getClient(cordovaActivity, gso); + mGoogleSignInClient.signOut() + .addOnCompleteListener(cordovaActivity, new OnCompleteListener() { + @Override + public void onComplete(@NonNull Task task) { + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK)); + } + }); + }catch(Exception googleSignOutException){ + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK)); + } + } catch (Exception e) { handleExceptionWithContext(e, callbackContext); } From 76ade3cbde3de8b636ca1de1d844777c51cccbec Mon Sep 17 00:00:00 2001 From: Douglas Ianitsky Date: Fri, 3 Apr 2020 19:46:38 -0300 Subject: [PATCH 07/17] Added signInUserWithCustomToken AND signInUserAnonymously auth methods --- README.md | 39 +++++++++++++++++++++++++++++++++ src/android/FirebasePlugin.java | 37 +++++++++++++++++++++++++++++++ src/ios/FirebasePlugin.h | 2 ++ src/ios/FirebasePlugin.m | 32 +++++++++++++++++++++++++++ types/index.d.ts | 9 ++++++++ www/firebase.js | 8 +++++++ 6 files changed, 127 insertions(+) diff --git a/README.md b/README.md index c3099490d..63ead5f2b 100644 --- a/README.md +++ b/README.md @@ -126,6 +126,8 @@ To help ensure this plugin is kept updated, new features are added and bugfixes - [deleteUser](#deleteuser) - [createUserWithEmailAndPassword](#createuserwithemailandpassword) - [signInUserWithEmailAndPassword](#signinuserwithemailandpassword) + - [signInUserWithCustomToken](#signInUserWithCustomToken) + - [signInUserAnonymously](#signInUserAnonymously) - [verifyPhoneNumber](#verifyphonenumber) - [Android](#android-2) - [iOS](#ios-2) @@ -2130,6 +2132,43 @@ Example usage: }); ``` +### signInUserWithCustomToken +Signs in user with custom token. + +**Parameters**: +- {string} customToken - the custom token +- {function} success - callback function to call on success +- {function} error - callback function which will be passed a {string} error message as an argument + +Example usage: + +```javascript + FirebasePlugin.signInUserWithCustomToken(customToken, function() { + console.log("Successfully signed in"); + // User is now signed in + }, function(error) { + console.error("Failed to sign in", error); + }); +``` + +### signInUserAnonymously +Signs in user anonymously. + +**Parameters**: +- {function} success - callback function to call on success +- {function} error - callback function which will be passed a {string} error message as an argument + +Example usage: + +```javascript + FirebasePlugin.signInUserAnonymously(function() { + console.log("Successfully signed in"); + // User is now signed in + }, function(error) { + console.error("Failed to sign in", error); + }); +``` + ### verifyPhoneNumber Requests verification of a phone number. The resulting credential can be used to create/sign in to a phone number-based user account in your app or to link the phone number to an existing user account diff --git a/src/android/FirebasePlugin.java b/src/android/FirebasePlugin.java index d5c89e18f..42a4bbc92 100755 --- a/src/android/FirebasePlugin.java +++ b/src/android/FirebasePlugin.java @@ -276,6 +276,12 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo } else if (action.equals("signInUserWithEmailAndPassword")) { this.signInUserWithEmailAndPassword(callbackContext, args); return true; + } else if (action.equals("signInUserWithCustomToken")) { + this.signInUserWithCustomToken(callbackContext, args); + return true; + } else if (action.equals("signInUserAnonymously")) { + this.signInUserAnonymously(callbackContext); + return true; } else if (action.equals("signInWithCredential")) { this.signInWithCredential(callbackContext, args); return true; @@ -1524,6 +1530,37 @@ public void run() { }); } + public void signInUserWithCustomToken(final CallbackContext callbackContext, final JSONArray args){ + cordova.getThreadPool().execute(new Runnable() { + public void run() { + try { + String customToken = args.getString(0); + + if(customToken == null || customToken.equals("")){ + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, "Custom token must be specified")); + return; + } + + FirebaseAuth.getInstance().signInWithCustomToken(customToken).addOnCompleteListener(cordova.getActivity(), new AuthResultOnCompleteListener(callbackContext)); + } catch (Exception e) { + handleExceptionWithContext(e, callbackContext); + } + } + }); + } + + public void signInUserAnonymously(final CallbackContext callbackContext){ + cordova.getThreadPool().execute(new Runnable() { + public void run() { + try { + FirebaseAuth.getInstance().signInAnonymously().addOnCompleteListener(cordova.getActivity(), new AuthResultOnCompleteListener(callbackContext)); + } catch (Exception e) { + handleExceptionWithContext(e, callbackContext); + } + } + }); + } + // // Firebase Performace // diff --git a/src/ios/FirebasePlugin.h b/src/ios/FirebasePlugin.h index b0870150a..44c1ee0ad 100644 --- a/src/ios/FirebasePlugin.h +++ b/src/ios/FirebasePlugin.h @@ -12,6 +12,8 @@ - (void)verifyPhoneNumber:(CDVInvokedUrlCommand*)command; - (void)createUserWithEmailAndPassword:(CDVInvokedUrlCommand*)command; - (void)signInUserWithEmailAndPassword:(CDVInvokedUrlCommand*)command; +- (void)signInUserWithCustomToken:(CDVInvokedUrlCommand*)command; +- (void)signInUserAnonymously:(CDVInvokedUrlCommand*)command; - (void)authenticateUserWithGoogle:(CDVInvokedUrlCommand*)command; - (void)authenticateUserWithApple:(CDVInvokedUrlCommand*)command; - (void)signInWithCredential:(CDVInvokedUrlCommand*)command; diff --git a/src/ios/FirebasePlugin.m b/src/ios/FirebasePlugin.m index dc92835c5..026c4717e 100644 --- a/src/ios/FirebasePlugin.m +++ b/src/ios/FirebasePlugin.m @@ -557,6 +557,38 @@ - (void)signInUserWithEmailAndPassword:(CDVInvokedUrlCommand*)command { } } +- (void)signInUserWithCustomToken:(CDVInvokedUrlCommand*)command { + @try { + NSString* customToken = [command.arguments objectAtIndex:0]; + [[FIRAuth auth] signInWithCustomToken:customToken + completion:^(FIRAuthDataResult * _Nullable authResult, + NSError * _Nullable error) { + @try { + [self handleAuthResult:authResult error:error command:command]; + }@catch (NSException *exception) { + [self handlePluginExceptionWithContext:exception :command]; + } + }]; + }@catch (NSException *exception) { + [self handlePluginExceptionWithContext:exception :command]; + } +} + +- (void)signInUserAnonymously:(CDVInvokedUrlCommand*)command { + @try { + [[FIRAuth auth] signInAnonymouslyWithCompletion:^(FIRAuthDataResult * _Nullable authResult, + NSError * _Nullable error) { + @try { + [self handleAuthResult:authResult error:error command:command]; + }@catch (NSException *exception) { + [self handlePluginExceptionWithContext:exception :command]; + } + }]; + }@catch (NSException *exception) { + [self handlePluginExceptionWithContext:exception :command]; + } +} + - (void)authenticateUserWithGoogle:(CDVInvokedUrlCommand*)command{ @try { self.googleSignInCallbackId = command.callbackId; diff --git a/types/index.d.ts b/types/index.d.ts index a23980b40..e9cf84aca 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -136,6 +136,15 @@ interface FirebasePlugin { success?: () => void, error?: (err: string) => void ): void + signInUserWithCustomToken( + customToken: string, + success?: () => void, + error?: (err: string) => void + ): void + signInUserAnonymously( + success?: () => void, + error?: (err: string) => void + ): void authenticateUserWithGoogle( clientId: string, success?: () => void, diff --git a/www/firebase.js b/www/firebase.js index 3982d96b1..5ac54cb2c 100644 --- a/www/firebase.js +++ b/www/firebase.js @@ -250,6 +250,14 @@ exports.signInUserWithEmailAndPassword = function (email, password, success, err exec(success, error, "FirebasePlugin", "signInUserWithEmailAndPassword", [email, password]); }; +exports.signInUserWithCustomToken = function (customToken, success, error) { + exec(success, error, "FirebasePlugin", "signInUserWithCustomToken", [customToken]); +}; + +exports.signInUserAnonymously = function (success, error) { + exec(success, error, "FirebasePlugin", "signInUserAnonymously"); +}; + exports.authenticateUserWithGoogle = function (clientId, success, error) { exec(success, error, "FirebasePlugin", "authenticateUserWithGoogle", [clientId]); }; From 3408872021b0ef6149e4bb6ea21c25cf9b3f2a61 Mon Sep 17 00:00:00 2001 From: Douglas Ianitsky Date: Sat, 4 Apr 2020 10:23:53 -0300 Subject: [PATCH 08/17] Added isAnonymous user information --- src/android/FirebasePlugin.java | 1 + src/ios/FirebasePlugin.m | 1 + 2 files changed, 2 insertions(+) diff --git a/src/android/FirebasePlugin.java b/src/android/FirebasePlugin.java index 42a4bbc92..fae22201e 100755 --- a/src/android/FirebasePlugin.java +++ b/src/android/FirebasePlugin.java @@ -1038,6 +1038,7 @@ public void run() { returnResults.put("photoUrl", user.getPhotoUrl() == null ? null : user.getPhotoUrl().toString()); returnResults.put("uid", user.getUid()); returnResults.put("providerId", user.getProviderId()); + returnResults.put("isAnonymous", user.isAnonymous()); user.getIdToken(true).addOnSuccessListener(new OnSuccessListener() { @Override diff --git a/src/ios/FirebasePlugin.m b/src/ios/FirebasePlugin.m index 026c4717e..d2dcf44f6 100644 --- a/src/ios/FirebasePlugin.m +++ b/src/ios/FirebasePlugin.m @@ -717,6 +717,7 @@ - (void)getCurrentUser:(CDVInvokedUrlCommand *)command { [userInfo setValue:user.photoURL ? user.photoURL.absoluteString : nil forKey:@"photoUrl"]; [userInfo setValue:user.uid forKey:@"uid"]; [userInfo setValue:user.providerID forKey:@"providerId"]; + [userInfo setValue:user.isAnonymous forKey:@"isAnonymous"]; [user getIDTokenWithCompletion:^(NSString * _Nullable token, NSError * _Nullable error) { [userInfo setValue:token forKey:@"idToken"]; [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:userInfo] callbackId:command.callbackId]; From 9cd0c08d00e8d9b1af86c06bf7c6f2d1ec3e7e00 Mon Sep 17 00:00:00 2001 From: Dave Alden Date: Sun, 5 Apr 2020 22:04:46 +0100 Subject: [PATCH 09/17] [iOS] Sign out of Google when signing out of Firebase. Resolves #353. --- CHANGELOG.md | 1 + src/ios/FirebasePlugin.m | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 168f3bcd2..dd5671c5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ * (Android): Don't display app icon for large notification icon on Android. Resolves [#343](https://github.com/dpa99c/cordova-plugin-firebasex/issues/343). +* (Android & iOS) Sign out of Google signing out of Firebase. Resolves [#353](https://github.com/dpa99c/cordova-plugin-firebasex/issues/353). # Version 9.0.1 * Re-add Firebase Inapp Messaging SDK component to master branch. diff --git a/src/ios/FirebasePlugin.m b/src/ios/FirebasePlugin.m index dc92835c5..818ee7402 100644 --- a/src/ios/FirebasePlugin.m +++ b/src/ios/FirebasePlugin.m @@ -656,6 +656,13 @@ - (void)signOutUser:(CDVInvokedUrlCommand*)command { [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"No user is currently signed"] callbackId:command.callbackId]; return; } + + // Sign out of Google + if([[GIDSignIn sharedInstance] currentUser] != nil){ + [[GIDSignIn sharedInstance] signOut]; + } + + // Sign out of Firebase NSError *signOutError; BOOL status = [[FIRAuth auth] signOut:&signOutError]; if (!status) { From 130e872c34d873d082217c0eb234f99be1e9555e Mon Sep 17 00:00:00 2001 From: Dave Alden Date: Sun, 5 Apr 2020 22:52:43 +0100 Subject: [PATCH 10/17] (Android & iOS) Add documentExistsInFirestoreCollection() and fix resolution of fetchDocumentInFirestoreCollection(). --- CHANGELOG.md | 1 + README.md | 21 +++++++++++++++ src/android/FirebasePlugin.java | 45 ++++++++++++++++++++++++++++++++- src/ios/FirebasePlugin.h | 1 + src/ios/FirebasePlugin.m | 31 +++++++++++++++++++++-- www/firebase.js | 7 +++++ 6 files changed, 103 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd5671c5d..a23b6b455 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ * (Android): Don't display app icon for large notification icon on Android. Resolves [#343](https://github.com/dpa99c/cordova-plugin-firebasex/issues/343). * (Android & iOS) Sign out of Google signing out of Firebase. Resolves [#353](https://github.com/dpa99c/cordova-plugin-firebasex/issues/353). +* (Android & iOS) Add `documentExistsInFirestoreCollection()` and fix resolution of `fetchDocumentInFirestoreCollection()`. # Version 9.0.1 * Re-add Firebase Inapp Messaging SDK component to master branch. diff --git a/README.md b/README.md index c3099490d..1533e2568 100644 --- a/README.md +++ b/README.md @@ -157,6 +157,7 @@ To help ensure this plugin is kept updated, new features are added and bugfixes - [setDocumentInFirestoreCollection](#setdocumentinfirestorecollection) - [updateDocumentInFirestoreCollection](#updatedocumentinfirestorecollection) - [deleteDocumentFromFirestoreCollection](#deletedocumentfromfirestorecollection) + - [documentExistsInFirestoreCollection](#documentexistsinfirestorecollection) - [fetchDocumentInFirestoreCollection](#fetchdocumentinfirestorecollection) - [fetchFirestoreCollection](#fetchfirestorecollection) - [Credits](#credits) @@ -2721,6 +2722,26 @@ FirebasePlugin.deleteDocumentFromFirestoreCollection(documentId, collection, fun }); ``` +### documentExistsInFirestoreCollection +Indicates if a document with the given ID exists in a Firestore collection. + +**Parameters**: +- {string} documentId - document ID of the document. +- {string} collection - name of top-level collection to check for document. +- {function} success - callback function to call pass result. +Will be passed an {boolean} which is `true` if a document exists. +- {function} error - callback function which will be passed a {string} error message as an argument. + +```javascript +var documentId = "my_doc"; +var collection = "my_collection"; +FirebasePlugin.documentExistsInFirestoreCollection(documentId, collection, function(exists){ + console.log("Document " + (exists ? "exists" : "doesn't exist")); +}, function(error){ + console.error("Error fetching document: "+error); +}); +``` + ### fetchDocumentInFirestoreCollection Fetches an existing document with the given ID from a Firestore collection. diff --git a/src/android/FirebasePlugin.java b/src/android/FirebasePlugin.java index 283ea7d7b..4d828b4dc 100755 --- a/src/android/FirebasePlugin.java +++ b/src/android/FirebasePlugin.java @@ -377,6 +377,9 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo } else if (action.equals("deleteDocumentFromFirestoreCollection")) { this.deleteDocumentFromFirestoreCollection(args, callbackContext); return true; + } else if (action.equals("documentExistsInFirestoreCollection")) { + this.documentExistsInFirestoreCollection(args, callbackContext); + return true; } else if (action.equals("fetchDocumentInFirestoreCollection")) { this.fetchDocumentInFirestoreCollection(args, callbackContext); return true; @@ -2084,6 +2087,46 @@ public void onFailure(@NonNull Exception e) { }); } + private void documentExistsInFirestoreCollection(JSONArray args, CallbackContext callbackContext) throws JSONException { + cordova.getThreadPool().execute(new Runnable() { + public void run() { + try { + String documentId = args.getString(0); + String collection = args.getString(1); + + firestore.collection(collection).document(documentId) + .get() + .addOnCompleteListener(new OnCompleteListener() { + @Override + public void onComplete(@NonNull Task task) { + try { + if (task.isSuccessful()) { + DocumentSnapshot document = task.getResult(); + callbackContext.success(document != null && document.getData() != null ? 1 : 0); + } else { + Exception e = task.getException(); + if(e != null){ + handleExceptionWithContext(e, callbackContext); + } + } + } catch (Exception e) { + handleExceptionWithContext(e, callbackContext); + } + } + }) + .addOnFailureListener(new OnFailureListener() { + @Override + public void onFailure(@NonNull Exception e) { + handleExceptionWithContext(e, callbackContext); + } + }); + } catch (Exception e) { + handleExceptionWithContext(e, callbackContext); + } + } + }); + } + private void fetchDocumentInFirestoreCollection(JSONArray args, CallbackContext callbackContext) throws JSONException { cordova.getThreadPool().execute(new Runnable() { public void run() { @@ -2099,7 +2142,7 @@ public void onComplete(@NonNull Task task) { try { if (task.isSuccessful()) { DocumentSnapshot document = task.getResult(); - if (document != null) { + if (document != null && document.getData() != null) { JSONObject jsonDoc = mapToJsonObject(document.getData()); callbackContext.success(jsonDoc); } else { diff --git a/src/ios/FirebasePlugin.h b/src/ios/FirebasePlugin.h index b0870150a..27d9e09c1 100644 --- a/src/ios/FirebasePlugin.h +++ b/src/ios/FirebasePlugin.h @@ -81,6 +81,7 @@ - (void)setDocumentInFirestoreCollection:(CDVInvokedUrlCommand*)command; - (void)updateDocumentInFirestoreCollection:(CDVInvokedUrlCommand*)command; - (void)deleteDocumentFromFirestoreCollection:(CDVInvokedUrlCommand*)command; +- (void)documentExistsInFirestoreCollection:(CDVInvokedUrlCommand*)command; - (void)fetchDocumentInFirestoreCollection:(CDVInvokedUrlCommand*)command; - (void)fetchFirestoreCollection:(CDVInvokedUrlCommand*)command; diff --git a/src/ios/FirebasePlugin.m b/src/ios/FirebasePlugin.m index 818ee7402..53b41f3fb 100644 --- a/src/ios/FirebasePlugin.m +++ b/src/ios/FirebasePlugin.m @@ -1383,6 +1383,31 @@ - (void)deleteDocumentFromFirestoreCollection:(CDVInvokedUrlCommand*)command { }]; } +- (void)documentExistsInFirestoreCollection:(CDVInvokedUrlCommand*)command { + [self.commandDelegate runInBackground:^{ + @try { + NSString* documentId = [command.arguments objectAtIndex:0]; + NSString* collection = [command.arguments objectAtIndex:1]; + + FIRDocumentReference* docRef = [[firestore collectionWithPath:collection] documentWithPath:documentId]; + if(docRef != nil){ + [docRef getDocumentWithCompletion:^(FIRDocumentSnapshot * _Nullable snapshot, NSError * _Nullable error) { + if (error != nil) { + [self sendPluginError:error.localizedDescription:command]; + }else{ + BOOL docExists = snapshot.data != nil; + [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:docExists] callbackId:command.callbackId]; + } + }]; + }else{ + [self sendPluginError:@"Collection not found":command]; + } + }@catch (NSException *exception) { + [self handlePluginExceptionWithContext:exception :command]; + } + }]; +} + - (void)fetchDocumentInFirestoreCollection:(CDVInvokedUrlCommand*)command { [self.commandDelegate runInBackground:^{ @try { @@ -1394,12 +1419,14 @@ - (void)fetchDocumentInFirestoreCollection:(CDVInvokedUrlCommand*)command { [docRef getDocumentWithCompletion:^(FIRDocumentSnapshot * _Nullable snapshot, NSError * _Nullable error) { if (error != nil) { [self sendPluginError:error.localizedDescription:command]; - } else { + } else if(snapshot.data != nil) { [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:snapshot.data] callbackId:command.callbackId]; + }else{ + [self sendPluginError:@"Document not found in collection":command]; } }]; }else{ - [self sendPluginError:@"Document not found in collection":command]; + [self sendPluginError:@"Collection not found":command]; } }@catch (NSException *exception) { [self handlePluginExceptionWithContext:exception :command]; diff --git a/www/firebase.js b/www/firebase.js index 3982d96b1..57ec81207 100644 --- a/www/firebase.js +++ b/www/firebase.js @@ -353,6 +353,13 @@ exports.deleteDocumentFromFirestoreCollection = function (documentId, collection exec(success, error, "FirebasePlugin", "deleteDocumentFromFirestoreCollection", [documentId.toString(), collection]); }; +exports.documentExistsInFirestoreCollection = function (documentId, collection, success, error) { + if(typeof documentId !== 'string' && typeof documentId !== 'number') return error("'documentId' must be a string or number specifying the Firestore document identifier"); + if(typeof collection !== 'string') return error("'collection' must be a string specifying the Firestore collection name"); + + exec(ensureBooleanFn(success), error, "FirebasePlugin", "documentExistsInFirestoreCollection", [documentId.toString(), collection]); +}; + exports.fetchDocumentInFirestoreCollection = function (documentId, collection, success, error) { if(typeof documentId !== 'string' && typeof documentId !== 'number') return error("'documentId' must be a string or number specifying the Firestore document identifier"); if(typeof collection !== 'string') return error("'collection' must be a string specifying the Firestore collection name"); From db1570b2dc2f558cdcccab4e8946d41cf7f966af Mon Sep 17 00:00:00 2001 From: Dave Alden Date: Tue, 7 Apr 2020 19:56:48 +0100 Subject: [PATCH 11/17] Patch version: 9.0.2 --- CHANGELOG.md | 1 + package.json | 2 +- plugin.xml | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a23b6b455..954a73bc4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +# Version 9.0.2 * (Android): Don't display app icon for large notification icon on Android. Resolves [#343](https://github.com/dpa99c/cordova-plugin-firebasex/issues/343). * (Android & iOS) Sign out of Google signing out of Firebase. Resolves [#353](https://github.com/dpa99c/cordova-plugin-firebasex/issues/353). * (Android & iOS) Add `documentExistsInFirestoreCollection()` and fix resolution of `fetchDocumentInFirestoreCollection()`. diff --git a/package.json b/package.json index 296404c2a..14186877c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-firebasex", - "version": "9.0.1", + "version": "9.0.2", "description": "Cordova plugin for Google Firebase", "types": "./types/index.d.ts", "author": { diff --git a/plugin.xml b/plugin.xml index 4d70d1e22..513d0762a 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,5 +1,5 @@ - Google Firebase Plugin From 7c81a9af6b2bd0d1c8124af301d37ca641fc0da1 Mon Sep 17 00:00:00 2001 From: Edmundas Rakauskas Date: Wed, 8 Apr 2020 23:39:37 +0300 Subject: [PATCH 12/17] adding getInfo method for iOS which should return some firebase remote config settings and other info regarding last fetch timing and status --- src/ios/FirebasePlugin.h | 1 + src/ios/FirebasePlugin.m | 121 ++++++++++++++++++++++++--------------- 2 files changed, 77 insertions(+), 45 deletions(-) diff --git a/src/ios/FirebasePlugin.h b/src/ios/FirebasePlugin.h index 27d9e09c1..2f4c8085f 100644 --- a/src/ios/FirebasePlugin.h +++ b/src/ios/FirebasePlugin.h @@ -68,6 +68,7 @@ - (void)fetch:(CDVInvokedUrlCommand*)command; - (void)activateFetched:(CDVInvokedUrlCommand*)command; - (void)getValue:(CDVInvokedUrlCommand*)command; +- (void)getInfo:(CDVInvokedUrlCommand*)command; // Performance - (void)setPerformanceCollectionEnabled:(CDVInvokedUrlCommand*)command; diff --git a/src/ios/FirebasePlugin.m b/src/ios/FirebasePlugin.m index 53b41f3fb..1d26cf2ec 100644 --- a/src/ios/FirebasePlugin.m +++ b/src/ios/FirebasePlugin.m @@ -57,31 +57,31 @@ + (void) setFirestore:(FIRFirestore*) firestoreInstance{ - (void)pluginInitialize { NSLog(@"Starting Firebase plugin"); firebasePlugin = self; - + @try { preferences = [NSUserDefaults standardUserDefaults]; googlePlist = [NSMutableDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"GoogleService-Info" ofType:@"plist"]]; - + if(![self getGooglePlistFlagWithDefaultValue:FIREBASE_CRASHLYTICS_COLLECTION_ENABLED defaultValue:YES]){ isCrashlyticsEnabled = [self getPreferenceFlag:FIREBASE_CRASHLYTICS_COLLECTION_ENABLED]; }else{ isCrashlyticsEnabled = YES; [self setPreferenceFlag:FIREBASE_CRASHLYTICS_COLLECTION_ENABLED flag:YES]; } - + if([self getGooglePlistFlagWithDefaultValue:FIREBASE_ANALYTICS_COLLECTION_ENABLED defaultValue:YES]){ [self setPreferenceFlag:FIREBASE_ANALYTICS_COLLECTION_ENABLED flag:YES]; } - + if([self getGooglePlistFlagWithDefaultValue:FIREBASE_PERFORMANCE_COLLECTION_ENABLED defaultValue:YES]){ [self setPreferenceFlag:FIREBASE_PERFORMANCE_COLLECTION_ENABLED flag:YES]; } - + // Check for permission and register for remote notifications if granted [self _hasPermission:^(BOOL result) {}]; - + [GIDSignIn sharedInstance].presentingViewController = self.viewController; - + authCredentials = [[NSMutableDictionary alloc] init]; }@catch (NSException *exception) { [self handlePluginExceptionWithoutContext:exception]; @@ -167,7 +167,7 @@ - (void)getToken:(CDVInvokedUrlCommand *)command { }else{ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:error.description]; } - + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; }]; }@catch (NSException *exception) { @@ -200,7 +200,7 @@ - (NSString *)hexadecimalStringFromData:(NSData *)data if (dataLength == 0) { return nil; } - + const unsigned char *dataBuffer = data.bytes; NSMutableString *hexString = [NSMutableString stringWithCapacity:(dataLength * 2)]; for (int i = 0; i < dataLength; ++i) { @@ -285,7 +285,7 @@ - (void)grantPermission:(CDVInvokedUrlCommand *)command { - (void)registerForRemoteNotifications { NSLog(@"registerForRemoteNotifications"); if(registeredForRemoteNotifications) return; - + [self runOnMainThread:^{ @try { [[UIApplication sharedApplication] registerForRemoteNotifications]; @@ -317,7 +317,7 @@ - (void)getBadgeNumber:(CDVInvokedUrlCommand *)command { [self runOnMainThread:^{ @try { long badge = [[UIApplication sharedApplication] applicationIconBadgeNumber]; - + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDouble:badge]; [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; }@catch (NSException *exception) { @@ -476,7 +476,7 @@ - (void)clearAllNotifications:(CDVInvokedUrlCommand *)command { @try { [[UIApplication sharedApplication] setApplicationIconBadgeNumber:1]; [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0]; - + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; }@catch (NSException *exception) { @@ -561,7 +561,7 @@ - (void)authenticateUserWithGoogle:(CDVInvokedUrlCommand*)command{ @try { self.googleSignInCallbackId = command.callbackId; [[GIDSignIn sharedInstance] signIn]; - + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_NO_RESULT]; [pluginResult setKeepCallbackAsBool:YES]; [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; @@ -576,13 +576,13 @@ - (void)authenticateUserWithApple:(CDVInvokedUrlCommand*)command{ if (@available(iOS 13.0, *)) { self.appleSignInCallbackId = command.callbackId; [self startSignInWithAppleFlow]; - + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_NO_RESULT]; [pluginResult setKeepCallbackAsBool:YES]; } else { pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"OS version is too low - Apple Sign In requires iOS 13.0+"]; } - + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; }@catch (NSException *exception) { [self handlePluginExceptionWithContext:exception :command]; @@ -593,7 +593,7 @@ - (void)signInWithCredential:(CDVInvokedUrlCommand*)command { @try { FIRAuthCredential* credential = [self obtainAuthCredential:[command.arguments objectAtIndex:0] command:command]; if(credential == nil) return; - + [[FIRAuth auth] signInWithCredential:credential completion:^(FIRAuthDataResult * _Nullable authResult, NSError * _Nullable error) { @@ -611,10 +611,10 @@ - (void)reauthenticateWithCredential:(CDVInvokedUrlCommand*)command{ [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"No user is currently signed"] callbackId:command.callbackId]; return; } - + FIRAuthCredential* credential = [self obtainAuthCredential:[command.arguments objectAtIndex:0] command:command]; if(credential == nil) return; - + [user reauthenticateWithCredential:credential completion:^(FIRAuthDataResult * _Nullable authResult, NSError * _Nullable error) { [self handleAuthResult:authResult error:error command:command]; }]; @@ -627,13 +627,13 @@ - (void)linkUserWithCredential:(CDVInvokedUrlCommand*)command { @try { FIRAuthCredential* credential = [self obtainAuthCredential:[command.arguments objectAtIndex:0] command:command]; if(credential == nil) return; - + [[FIRAuth auth].currentUser linkWithCredential:credential completion:^(FIRAuthDataResult * _Nullable authResult, NSError * _Nullable error) { [self handleAuthResult:authResult error:error command:command]; }]; - + }@catch (NSException *exception) { [self handlePluginExceptionWithContext:exception :command]; } @@ -643,7 +643,7 @@ - (void)isUserSignedIn:(CDVInvokedUrlCommand*)command { @try { bool isSignedIn = [FIRAuth auth].currentUser ? true : false; [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:isSignedIn] callbackId:command.callbackId]; - + }@catch (NSException *exception) { [self handlePluginExceptionWithContext:exception :command]; } @@ -656,12 +656,12 @@ - (void)signOutUser:(CDVInvokedUrlCommand*)command { [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"No user is currently signed"] callbackId:command.callbackId]; return; } - + // Sign out of Google if([[GIDSignIn sharedInstance] currentUser] != nil){ [[GIDSignIn sharedInstance] signOut]; } - + // Sign out of Firebase NSError *signOutError; BOOL status = [[FIRAuth auth] signOut:&signOutError]; @@ -676,14 +676,14 @@ - (void)signOutUser:(CDVInvokedUrlCommand*)command { } - (void)getCurrentUser:(CDVInvokedUrlCommand *)command { - + @try { FIRUser* user = [FIRAuth auth].currentUser; if(!user){ [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"No user is currently signed"] callbackId:command.callbackId]; return; } - + NSMutableDictionary* userInfo = [NSMutableDictionary new]; [userInfo setValue:user.displayName forKey:@"name"]; [userInfo setValue:user.email forKey:@"email"]; @@ -708,9 +708,9 @@ - (void)updateUserProfile:(CDVInvokedUrlCommand*)command { [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"No user is currently signed"] callbackId:command.callbackId]; return; } - + NSDictionary* profile = [command.arguments objectAtIndex:0]; - + FIRUserProfileChangeRequest* changeRequest = [user profileChangeRequest]; if([profile objectForKey:@"name"] != nil){ changeRequest.displayName = [profile objectForKey:@"name"]; @@ -718,7 +718,7 @@ - (void)updateUserProfile:(CDVInvokedUrlCommand*)command { if([profile objectForKey:@"photoUri"] != nil){ changeRequest.photoURL = [NSURL URLWithString:[profile objectForKey:@"photoUri"]]; } - + [changeRequest commitChangesWithCompletion:^(NSError *_Nullable error) { @try { [self handleResultWithPotentialError:error command:command]; @@ -738,7 +738,7 @@ - (void)updateUserEmail:(CDVInvokedUrlCommand*)command { [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"No user is currently signed"] callbackId:command.callbackId]; return; } - + NSString* email = [command.arguments objectAtIndex:0]; [user updateEmail:email completion:^(NSError *_Nullable error) { @try { @@ -759,7 +759,7 @@ - (void)sendUserEmailVerification:(CDVInvokedUrlCommand*)command{ [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"No user is currently signed"] callbackId:command.callbackId]; return; } - + [user sendEmailVerificationWithCompletion:^(NSError *_Nullable error) { @try { [self handleResultWithPotentialError:error command:command]; @@ -779,7 +779,7 @@ - (void)updateUserPassword:(CDVInvokedUrlCommand*)command{ [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"No user is currently signed"] callbackId:command.callbackId]; return; } - + NSString* password = [command.arguments objectAtIndex:0]; [user updatePassword:password completion:^(NSError *_Nullable error) { @try { @@ -815,7 +815,7 @@ - (void)deleteUser:(CDVInvokedUrlCommand*)command{ [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"No user is currently signed"] callbackId:command.callbackId]; return; } - + [user deleteWithCompletion:^(NSError *_Nullable error) { @try { [self handleResultWithPotentialError:error command:command]; @@ -1006,7 +1006,7 @@ - (void)setCrashlyticsCollectionEnabled:(CDVInvokedUrlCommand *)command { [self setPreferenceFlag:FIREBASE_CRASHLYTICS_COLLECTION_ENABLED flag:enabled]; pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; } - + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; }@catch (NSException *exception) { [self handlePluginExceptionWithContext:exception :command]; @@ -1039,7 +1039,7 @@ - (void)isCrashlyticsCollectionCurrentlyEnabled:(CDVInvokedUrlCommand*)command{ - (void)logError:(CDVInvokedUrlCommand *)command { [self.commandDelegate runInBackground:^{ NSString* errorMessage = [command.arguments objectAtIndex:0]; - + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; @try { if(!isCrashlyticsEnabled){ @@ -1048,11 +1048,11 @@ - (void)logError:(CDVInvokedUrlCommand *)command { // We can optionally be passed a stack trace from stackTrace.js which we'll put in userInfo. else if ([command.arguments count] > 1) { NSArray* stackFrames = [command.arguments objectAtIndex:1]; - + NSString* message = errorMessage; NSString* name = @"Uncaught Javascript exception"; NSMutableArray *customFrames = [[NSMutableArray alloc] init]; - + for (NSDictionary* stackFrame in stackFrames) { CLSStackFrame *customFrame = [CLSStackFrame stackFrame]; [customFrame setSymbol:stackFrame[@"functionName"]]; @@ -1073,7 +1073,7 @@ - (void)logError:(CDVInvokedUrlCommand *)command { } @catch (NSException *exception) { [self handlePluginExceptionWithContext:exception :command]; } - + }]; } @@ -1187,6 +1187,37 @@ - (void)getValue:(CDVInvokedUrlCommand *)command { }]; } +- (void)getInfo:(CDVInvokedUrlCommand *)command { + [self.commandDelegate runInBackground:^{ + @try { + FIRRemoteConfig* remoteConfig = [FIRRemoteConfig remoteConfig]; + NSInteger minimumFetchInterval = remoteConfig.configSettings.minimumFetchInterval; + NSInteger fetchTimeout = remoteConfig.configSettings.fetchTimeout; + NSDate* lastFetchTime = remoteConfig.lastFetchTime; + FIRRemoteConfigFetchStatus lastFetchStatus = remoteConfig.lastFetchStatus; + // isDeveloperModeEnabled is deprecated new recommnded way to check is minimumFetchInterval == 0 + BOOL isDeveloperModeEnabled = minimumFetchInterval == 0 ? true : false; + + NSDictionary* configSettings = @{ + @"developerModeEnabled": [NSNumber numberWithBool:isDeveloperModeEnabled], + @"minimumFetchInterval": [NSNumber numberWithInteger:minimumFetchInterval], + @"fetchTimeout": [NSNumber numberWithInteger:fetchTimeout], + }; + + NSDictionary* infoObject = @{ + @"configSettings": configSettings, + @"fetchTimeMillis": (lastFetchTime ? [NSNumber numberWithInteger:(lastFetchTime.timeIntervalSince1970 * 1000)] : [NSNull null]), + @"lastFetchStatus": [NSNumber numberWithInteger:(lastFetchStatus)], + }; + + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:infoObject]; + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }@catch (NSException *exception) { + [self handlePluginExceptionWithContext:exception :command]; + } + }]; +} + /* * Performance */ @@ -1324,7 +1355,7 @@ - (void)setDocumentInFirestoreCollection:(CDVInvokedUrlCommand*)command { NSString* documentId = [command.arguments objectAtIndex:0]; NSDictionary* document = [command.arguments objectAtIndex:1]; NSString* collection = [command.arguments objectAtIndex:2]; - + [[[firestore collectionWithPath:collection] documentWithPath:documentId] setData:document completion:^(NSError * _Nullable error) { if (error != nil) { [self sendPluginError:error.localizedDescription:command]; @@ -1344,7 +1375,7 @@ - (void)updateDocumentInFirestoreCollection:(CDVInvokedUrlCommand*)command { NSString* documentId = [command.arguments objectAtIndex:0]; NSDictionary* document = [command.arguments objectAtIndex:1]; NSString* collection = [command.arguments objectAtIndex:2]; - + FIRDocumentReference* docRef = [[firestore collectionWithPath:collection] documentWithPath:documentId]; if(docRef != nil){ [docRef updateData:document completion:^(NSError * _Nullable error) { @@ -1388,7 +1419,7 @@ - (void)documentExistsInFirestoreCollection:(CDVInvokedUrlCommand*)command { @try { NSString* documentId = [command.arguments objectAtIndex:0]; NSString* collection = [command.arguments objectAtIndex:1]; - + FIRDocumentReference* docRef = [[firestore collectionWithPath:collection] documentWithPath:documentId]; if(docRef != nil){ [docRef getDocumentWithCompletion:^(FIRDocumentSnapshot * _Nullable snapshot, NSError * _Nullable error) { @@ -1413,7 +1444,7 @@ - (void)fetchDocumentInFirestoreCollection:(CDVInvokedUrlCommand*)command { @try { NSString* documentId = [command.arguments objectAtIndex:0]; NSString* collection = [command.arguments objectAtIndex:1]; - + FIRDocumentReference* docRef = [[firestore collectionWithPath:collection] documentWithPath:documentId]; if(docRef != nil){ [docRef getDocumentWithCompletion:^(FIRDocumentSnapshot * _Nullable snapshot, NSError * _Nullable error) { @@ -1530,17 +1561,17 @@ - (void)runOnMainThread:(void (^)(void))completeBlock { - (FIRAuthCredential*)obtainAuthCredential:(NSDictionary*)credential command:(CDVInvokedUrlCommand *)command { FIRAuthCredential* authCredential = nil; - + if(credential == nil){ NSString* errMsg = @"credential object must be passed as first and only argument"; [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:errMsg] callbackId:command.callbackId]; return authCredential; } - + NSString* key = [credential objectForKey:@"id"]; NSString* verificationId = [credential objectForKey:@"verificationId"]; NSString* code = [credential objectForKey:@"code"]; - + if(key != nil){ authCredential = [authCredentials objectForKey:key]; if(authCredential == nil){ @@ -1580,7 +1611,7 @@ - (int) saveAuthCredential: (FIRAuthCredential*) authCredential { while (key < 0 || [authCredentials objectForKey:[NSNumber numberWithInt:key]] != nil) { key = arc4random_uniform(100000); } - + [authCredentials setObject:authCredential forKey:[NSNumber numberWithInt:key]]; return key; From ee6b91f0af23798218122e3b38b7f2c4d62400bf Mon Sep 17 00:00:00 2001 From: Edmundas Rakauskas Date: Thu, 9 Apr 2020 00:07:54 +0300 Subject: [PATCH 13/17] updated getInfo readme --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1533e2568..864201b35 100644 --- a/README.md +++ b/README.md @@ -2469,7 +2469,6 @@ FirebasePlugin.getByteArray("key", function(bytes) { ``` ### getInfo -Android only. Get the current state of the FirebaseRemoteConfig singleton object: **Parameters**: @@ -2480,6 +2479,10 @@ Get the current state of the FirebaseRemoteConfig singleton object: FirebasePlugin.getInfo(function(info) { // the status of the developer mode setting (true/false) console.log(info.configSettings.developerModeEnabled); + // (iOS only) for how much (secs) fetch cache is valid and data will not be refetched + console.log(info.configSettings.minimumFetchInterval); + // (iOS only) value in seconds to abandon a pending fetch request made to the backend + console.log(info.configSettings.fetchTimeout); // the timestamp (milliseconds since epoch) of the last successful fetch console.log(info.fetchTimeMillis); // the status of the most recent fetch attempt (int) From d9bd6ea75a98e3ece5de008abece54b6b46d6752 Mon Sep 17 00:00:00 2001 From: Edmundas Rakauskas Date: Thu, 9 Apr 2020 00:11:09 +0300 Subject: [PATCH 14/17] restoring previous whitespace --- src/ios/FirebasePlugin.m | 90 ++++++++++++++++++++-------------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/src/ios/FirebasePlugin.m b/src/ios/FirebasePlugin.m index 1d26cf2ec..58ee06795 100644 --- a/src/ios/FirebasePlugin.m +++ b/src/ios/FirebasePlugin.m @@ -57,31 +57,31 @@ + (void) setFirestore:(FIRFirestore*) firestoreInstance{ - (void)pluginInitialize { NSLog(@"Starting Firebase plugin"); firebasePlugin = self; - + @try { preferences = [NSUserDefaults standardUserDefaults]; googlePlist = [NSMutableDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"GoogleService-Info" ofType:@"plist"]]; - + if(![self getGooglePlistFlagWithDefaultValue:FIREBASE_CRASHLYTICS_COLLECTION_ENABLED defaultValue:YES]){ isCrashlyticsEnabled = [self getPreferenceFlag:FIREBASE_CRASHLYTICS_COLLECTION_ENABLED]; }else{ isCrashlyticsEnabled = YES; [self setPreferenceFlag:FIREBASE_CRASHLYTICS_COLLECTION_ENABLED flag:YES]; } - + if([self getGooglePlistFlagWithDefaultValue:FIREBASE_ANALYTICS_COLLECTION_ENABLED defaultValue:YES]){ [self setPreferenceFlag:FIREBASE_ANALYTICS_COLLECTION_ENABLED flag:YES]; } - + if([self getGooglePlistFlagWithDefaultValue:FIREBASE_PERFORMANCE_COLLECTION_ENABLED defaultValue:YES]){ [self setPreferenceFlag:FIREBASE_PERFORMANCE_COLLECTION_ENABLED flag:YES]; } - + // Check for permission and register for remote notifications if granted [self _hasPermission:^(BOOL result) {}]; - + [GIDSignIn sharedInstance].presentingViewController = self.viewController; - + authCredentials = [[NSMutableDictionary alloc] init]; }@catch (NSException *exception) { [self handlePluginExceptionWithoutContext:exception]; @@ -167,7 +167,7 @@ - (void)getToken:(CDVInvokedUrlCommand *)command { }else{ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:error.description]; } - + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; }]; }@catch (NSException *exception) { @@ -200,7 +200,7 @@ - (NSString *)hexadecimalStringFromData:(NSData *)data if (dataLength == 0) { return nil; } - + const unsigned char *dataBuffer = data.bytes; NSMutableString *hexString = [NSMutableString stringWithCapacity:(dataLength * 2)]; for (int i = 0; i < dataLength; ++i) { @@ -285,7 +285,7 @@ - (void)grantPermission:(CDVInvokedUrlCommand *)command { - (void)registerForRemoteNotifications { NSLog(@"registerForRemoteNotifications"); if(registeredForRemoteNotifications) return; - + [self runOnMainThread:^{ @try { [[UIApplication sharedApplication] registerForRemoteNotifications]; @@ -317,7 +317,7 @@ - (void)getBadgeNumber:(CDVInvokedUrlCommand *)command { [self runOnMainThread:^{ @try { long badge = [[UIApplication sharedApplication] applicationIconBadgeNumber]; - + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDouble:badge]; [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; }@catch (NSException *exception) { @@ -476,7 +476,7 @@ - (void)clearAllNotifications:(CDVInvokedUrlCommand *)command { @try { [[UIApplication sharedApplication] setApplicationIconBadgeNumber:1]; [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0]; - + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; }@catch (NSException *exception) { @@ -561,7 +561,7 @@ - (void)authenticateUserWithGoogle:(CDVInvokedUrlCommand*)command{ @try { self.googleSignInCallbackId = command.callbackId; [[GIDSignIn sharedInstance] signIn]; - + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_NO_RESULT]; [pluginResult setKeepCallbackAsBool:YES]; [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; @@ -576,13 +576,13 @@ - (void)authenticateUserWithApple:(CDVInvokedUrlCommand*)command{ if (@available(iOS 13.0, *)) { self.appleSignInCallbackId = command.callbackId; [self startSignInWithAppleFlow]; - + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_NO_RESULT]; [pluginResult setKeepCallbackAsBool:YES]; } else { pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"OS version is too low - Apple Sign In requires iOS 13.0+"]; } - + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; }@catch (NSException *exception) { [self handlePluginExceptionWithContext:exception :command]; @@ -593,7 +593,7 @@ - (void)signInWithCredential:(CDVInvokedUrlCommand*)command { @try { FIRAuthCredential* credential = [self obtainAuthCredential:[command.arguments objectAtIndex:0] command:command]; if(credential == nil) return; - + [[FIRAuth auth] signInWithCredential:credential completion:^(FIRAuthDataResult * _Nullable authResult, NSError * _Nullable error) { @@ -611,10 +611,10 @@ - (void)reauthenticateWithCredential:(CDVInvokedUrlCommand*)command{ [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"No user is currently signed"] callbackId:command.callbackId]; return; } - + FIRAuthCredential* credential = [self obtainAuthCredential:[command.arguments objectAtIndex:0] command:command]; if(credential == nil) return; - + [user reauthenticateWithCredential:credential completion:^(FIRAuthDataResult * _Nullable authResult, NSError * _Nullable error) { [self handleAuthResult:authResult error:error command:command]; }]; @@ -627,13 +627,13 @@ - (void)linkUserWithCredential:(CDVInvokedUrlCommand*)command { @try { FIRAuthCredential* credential = [self obtainAuthCredential:[command.arguments objectAtIndex:0] command:command]; if(credential == nil) return; - + [[FIRAuth auth].currentUser linkWithCredential:credential completion:^(FIRAuthDataResult * _Nullable authResult, NSError * _Nullable error) { [self handleAuthResult:authResult error:error command:command]; }]; - + }@catch (NSException *exception) { [self handlePluginExceptionWithContext:exception :command]; } @@ -643,7 +643,7 @@ - (void)isUserSignedIn:(CDVInvokedUrlCommand*)command { @try { bool isSignedIn = [FIRAuth auth].currentUser ? true : false; [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:isSignedIn] callbackId:command.callbackId]; - + }@catch (NSException *exception) { [self handlePluginExceptionWithContext:exception :command]; } @@ -656,12 +656,12 @@ - (void)signOutUser:(CDVInvokedUrlCommand*)command { [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"No user is currently signed"] callbackId:command.callbackId]; return; } - + // Sign out of Google if([[GIDSignIn sharedInstance] currentUser] != nil){ [[GIDSignIn sharedInstance] signOut]; } - + // Sign out of Firebase NSError *signOutError; BOOL status = [[FIRAuth auth] signOut:&signOutError]; @@ -676,14 +676,14 @@ - (void)signOutUser:(CDVInvokedUrlCommand*)command { } - (void)getCurrentUser:(CDVInvokedUrlCommand *)command { - + @try { FIRUser* user = [FIRAuth auth].currentUser; if(!user){ [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"No user is currently signed"] callbackId:command.callbackId]; return; } - + NSMutableDictionary* userInfo = [NSMutableDictionary new]; [userInfo setValue:user.displayName forKey:@"name"]; [userInfo setValue:user.email forKey:@"email"]; @@ -708,9 +708,9 @@ - (void)updateUserProfile:(CDVInvokedUrlCommand*)command { [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"No user is currently signed"] callbackId:command.callbackId]; return; } - + NSDictionary* profile = [command.arguments objectAtIndex:0]; - + FIRUserProfileChangeRequest* changeRequest = [user profileChangeRequest]; if([profile objectForKey:@"name"] != nil){ changeRequest.displayName = [profile objectForKey:@"name"]; @@ -718,7 +718,7 @@ - (void)updateUserProfile:(CDVInvokedUrlCommand*)command { if([profile objectForKey:@"photoUri"] != nil){ changeRequest.photoURL = [NSURL URLWithString:[profile objectForKey:@"photoUri"]]; } - + [changeRequest commitChangesWithCompletion:^(NSError *_Nullable error) { @try { [self handleResultWithPotentialError:error command:command]; @@ -738,7 +738,7 @@ - (void)updateUserEmail:(CDVInvokedUrlCommand*)command { [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"No user is currently signed"] callbackId:command.callbackId]; return; } - + NSString* email = [command.arguments objectAtIndex:0]; [user updateEmail:email completion:^(NSError *_Nullable error) { @try { @@ -759,7 +759,7 @@ - (void)sendUserEmailVerification:(CDVInvokedUrlCommand*)command{ [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"No user is currently signed"] callbackId:command.callbackId]; return; } - + [user sendEmailVerificationWithCompletion:^(NSError *_Nullable error) { @try { [self handleResultWithPotentialError:error command:command]; @@ -779,7 +779,7 @@ - (void)updateUserPassword:(CDVInvokedUrlCommand*)command{ [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"No user is currently signed"] callbackId:command.callbackId]; return; } - + NSString* password = [command.arguments objectAtIndex:0]; [user updatePassword:password completion:^(NSError *_Nullable error) { @try { @@ -815,7 +815,7 @@ - (void)deleteUser:(CDVInvokedUrlCommand*)command{ [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"No user is currently signed"] callbackId:command.callbackId]; return; } - + [user deleteWithCompletion:^(NSError *_Nullable error) { @try { [self handleResultWithPotentialError:error command:command]; @@ -1006,7 +1006,7 @@ - (void)setCrashlyticsCollectionEnabled:(CDVInvokedUrlCommand *)command { [self setPreferenceFlag:FIREBASE_CRASHLYTICS_COLLECTION_ENABLED flag:enabled]; pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; } - + [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; }@catch (NSException *exception) { [self handlePluginExceptionWithContext:exception :command]; @@ -1039,7 +1039,7 @@ - (void)isCrashlyticsCollectionCurrentlyEnabled:(CDVInvokedUrlCommand*)command{ - (void)logError:(CDVInvokedUrlCommand *)command { [self.commandDelegate runInBackground:^{ NSString* errorMessage = [command.arguments objectAtIndex:0]; - + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; @try { if(!isCrashlyticsEnabled){ @@ -1048,11 +1048,11 @@ - (void)logError:(CDVInvokedUrlCommand *)command { // We can optionally be passed a stack trace from stackTrace.js which we'll put in userInfo. else if ([command.arguments count] > 1) { NSArray* stackFrames = [command.arguments objectAtIndex:1]; - + NSString* message = errorMessage; NSString* name = @"Uncaught Javascript exception"; NSMutableArray *customFrames = [[NSMutableArray alloc] init]; - + for (NSDictionary* stackFrame in stackFrames) { CLSStackFrame *customFrame = [CLSStackFrame stackFrame]; [customFrame setSymbol:stackFrame[@"functionName"]]; @@ -1073,7 +1073,7 @@ - (void)logError:(CDVInvokedUrlCommand *)command { } @catch (NSException *exception) { [self handlePluginExceptionWithContext:exception :command]; } - + }]; } @@ -1355,7 +1355,7 @@ - (void)setDocumentInFirestoreCollection:(CDVInvokedUrlCommand*)command { NSString* documentId = [command.arguments objectAtIndex:0]; NSDictionary* document = [command.arguments objectAtIndex:1]; NSString* collection = [command.arguments objectAtIndex:2]; - + [[[firestore collectionWithPath:collection] documentWithPath:documentId] setData:document completion:^(NSError * _Nullable error) { if (error != nil) { [self sendPluginError:error.localizedDescription:command]; @@ -1375,7 +1375,7 @@ - (void)updateDocumentInFirestoreCollection:(CDVInvokedUrlCommand*)command { NSString* documentId = [command.arguments objectAtIndex:0]; NSDictionary* document = [command.arguments objectAtIndex:1]; NSString* collection = [command.arguments objectAtIndex:2]; - + FIRDocumentReference* docRef = [[firestore collectionWithPath:collection] documentWithPath:documentId]; if(docRef != nil){ [docRef updateData:document completion:^(NSError * _Nullable error) { @@ -1419,7 +1419,7 @@ - (void)documentExistsInFirestoreCollection:(CDVInvokedUrlCommand*)command { @try { NSString* documentId = [command.arguments objectAtIndex:0]; NSString* collection = [command.arguments objectAtIndex:1]; - + FIRDocumentReference* docRef = [[firestore collectionWithPath:collection] documentWithPath:documentId]; if(docRef != nil){ [docRef getDocumentWithCompletion:^(FIRDocumentSnapshot * _Nullable snapshot, NSError * _Nullable error) { @@ -1444,7 +1444,7 @@ - (void)fetchDocumentInFirestoreCollection:(CDVInvokedUrlCommand*)command { @try { NSString* documentId = [command.arguments objectAtIndex:0]; NSString* collection = [command.arguments objectAtIndex:1]; - + FIRDocumentReference* docRef = [[firestore collectionWithPath:collection] documentWithPath:documentId]; if(docRef != nil){ [docRef getDocumentWithCompletion:^(FIRDocumentSnapshot * _Nullable snapshot, NSError * _Nullable error) { @@ -1561,17 +1561,17 @@ - (void)runOnMainThread:(void (^)(void))completeBlock { - (FIRAuthCredential*)obtainAuthCredential:(NSDictionary*)credential command:(CDVInvokedUrlCommand *)command { FIRAuthCredential* authCredential = nil; - + if(credential == nil){ NSString* errMsg = @"credential object must be passed as first and only argument"; [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:errMsg] callbackId:command.callbackId]; return authCredential; } - + NSString* key = [credential objectForKey:@"id"]; NSString* verificationId = [credential objectForKey:@"verificationId"]; NSString* code = [credential objectForKey:@"code"]; - + if(key != nil){ authCredential = [authCredentials objectForKey:key]; if(authCredential == nil){ @@ -1611,7 +1611,7 @@ - (int) saveAuthCredential: (FIRAuthCredential*) authCredential { while (key < 0 || [authCredentials objectForKey:[NSNumber numberWithInt:key]] != nil) { key = arc4random_uniform(100000); } - + [authCredentials setObject:authCredential forKey:[NSNumber numberWithInt:key]]; return key; From aede1851cdbba5f49a48969f75da7d5a5302f160 Mon Sep 17 00:00:00 2001 From: Douglas Date: Thu, 9 Apr 2020 19:05:46 -0300 Subject: [PATCH 15/17] Fix isAnonymous compile error --- src/ios/FirebasePlugin.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ios/FirebasePlugin.m b/src/ios/FirebasePlugin.m index d2dcf44f6..a1460352d 100644 --- a/src/ios/FirebasePlugin.m +++ b/src/ios/FirebasePlugin.m @@ -717,7 +717,7 @@ - (void)getCurrentUser:(CDVInvokedUrlCommand *)command { [userInfo setValue:user.photoURL ? user.photoURL.absoluteString : nil forKey:@"photoUrl"]; [userInfo setValue:user.uid forKey:@"uid"]; [userInfo setValue:user.providerID forKey:@"providerId"]; - [userInfo setValue:user.isAnonymous forKey:@"isAnonymous"]; + [userInfo setValue:@(user.isAnonymous ? true : false) forKey:@"isAnonymous"]; [user getIDTokenWithCompletion:^(NSString * _Nullable token, NSError * _Nullable error) { [userInfo setValue:token forKey:@"idToken"]; [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:userInfo] callbackId:command.callbackId]; From fc25b8a851e3eac42a9f37794416b8cf16fa3c15 Mon Sep 17 00:00:00 2001 From: Dave Alden Date: Fri, 10 Apr 2020 07:33:54 +0100 Subject: [PATCH 16/17] (Doc) Update ToC --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6a113d70c..b8c30a2de 100644 --- a/README.md +++ b/README.md @@ -126,8 +126,8 @@ To help ensure this plugin is kept updated, new features are added and bugfixes - [deleteUser](#deleteuser) - [createUserWithEmailAndPassword](#createuserwithemailandpassword) - [signInUserWithEmailAndPassword](#signinuserwithemailandpassword) - - [signInUserWithCustomToken](#signInUserWithCustomToken) - - [signInUserAnonymously](#signInUserAnonymously) + - [signInUserWithCustomToken](#signinuserwithcustomtoken) + - [signInUserAnonymously](#signinuseranonymously) - [verifyPhoneNumber](#verifyphonenumber) - [Android](#android-2) - [iOS](#ios-2) From 8dd611ac0e1f7dbe8ee37c797bd99bde4e1bd305 Mon Sep 17 00:00:00 2001 From: Dave Alden Date: Fri, 10 Apr 2020 07:45:36 +0100 Subject: [PATCH 17/17] (Doc) Document as-yet unreleased changes --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 954a73bc4..a6d155997 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +* (Doc) `createChannel()` suggestion for multiple sounds + * Merged from PR [#225](https://github.com/dpa99c/cordova-plugin-firebasex/pull/225). +* (iOS) Implement `getInfo()` for iOS. + * Merged from PR [#363](https://github.com/dpa99c/cordova-plugin-firebasex/pull/363). +* (Android & iOS) Add `signInUserWithCustomToken()` AND `signInUserAnonymously()` auth methods + * Merged from PR [#359](https://github.com/dpa99c/cordova-plugin-firebasex/pull/359). + # Version 9.0.2 * (Android): Don't display app icon for large notification icon on Android. Resolves [#343](https://github.com/dpa99c/cordova-plugin-firebasex/issues/343). * (Android & iOS) Sign out of Google signing out of Firebase. Resolves [#353](https://github.com/dpa99c/cordova-plugin-firebasex/issues/353).