diff --git a/CHANGELOG.md b/CHANGELOG.md
index 497b8dd3a..187068937 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-cli
* (Android): Don't display app icon for large notification icon on Android. Resolves [#343](https://github.com/dpa99c/cordova-plugin-firebasex/issues/343).
diff --git a/README.md b/README.md
index 8267c7423..15294265c 100644
--- a/README.md
+++ b/README.md
@@ -140,6 +140,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)
@@ -1575,6 +1577,30 @@ 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.
@@ -2128,6 +2154,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
@@ -2466,7 +2529,6 @@ FirebasePlugin.getByteArray("key", function(bytes) {
```
### getInfo
-Android only.
Get the current state of the FirebaseRemoteConfig singleton object:
**Parameters**:
@@ -2477,6 +2539,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)
diff --git a/plugin.xml b/plugin.xml
index a0e5ca1c2..a38613552 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -72,12 +72,14 @@
+
+
@@ -132,10 +134,12 @@
+
+
diff --git a/src/android/FirebasePlugin.java b/src/android/FirebasePlugin.java
index 4d828b4dc..731ef6d83 100755
--- a/src/android/FirebasePlugin.java
+++ b/src/android/FirebasePlugin.java
@@ -278,6 +278,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;
@@ -1053,6 +1059,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
@@ -1545,6 +1552,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 27d9e09c1..7b85040a3 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;
@@ -68,6 +70,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..c09862a4d 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;
@@ -692,6 +724,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 ? 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];
@@ -1187,6 +1220,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
*/
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 57ec81207..927e3589c 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]);
};