Skip to content

Commit

Permalink
Merge branch 'master' into cli_build
Browse files Browse the repository at this point in the history
  • Loading branch information
dpa99c committed Apr 10, 2020
2 parents edbe7e5 + 8dd611a commit b21213f
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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).
Expand Down
68 changes: 67 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -2466,7 +2529,6 @@ FirebasePlugin.getByteArray("key", function(bytes) {
```

### getInfo
Android only.
Get the current state of the FirebaseRemoteConfig singleton object:

**Parameters**:
Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,14 @@
<preference name="ANDROID_CRASHLYTICS_NDK_VERSION" default="2.1.1" />
<preference name="ANDROID_GSON_VERSION" default="2.8.6" />

<framework src="com.google.android.gms:play-services-tagmanager:$ANDROID_PLAY_SERVICES_TAGMANAGER_VERSION" />
<framework src="com.google.android.gms:play-services-auth:$ANDROID_PLAY_SERVICES_AUTH_VERSION" />
<framework src="com.google.firebase:firebase-analytics:$ANDROID_FIREBASE_ANALYTICS_VERSION" />
<framework src="com.google.firebase:firebase-messaging:$ANDROID_FIREBASE_MESSAGING_VERSION" />
<framework src="com.google.firebase:firebase-config:$ANDROID_FIREBASE_CONFIG_VERSION" />
<framework src="com.google.firebase:firebase-perf:$ANDROID_FIREBASE_PERF_VERSION" />
<framework src="com.google.firebase:firebase-auth:$ANDROID_FIREBASE_AUTH_VERSION" />
<framework src="com.google.firebase:firebase-inappmessaging-display:$ANDROID_FIREBASE_INAPPMESSAGING_VERSION" />
<framework src="com.google.firebase:firebase-firestore:$ANDROID_FIREBASE_FIRESTORE_VERSION" />
<framework src="com.crashlytics.sdk.android:crashlytics:$ANDROID_CRASHLYTICS_VERSION" />
<framework src="com.crashlytics.sdk.android:crashlytics-ndk:$ANDROID_CRASHLYTICS_NDK_VERSION" />
Expand Down Expand Up @@ -132,10 +134,12 @@
<pod name="Firebase/Messaging" spec="6.18.0"/>
<pod name="Firebase/Performance" spec="6.18.0"/>
<pod name="Firebase/RemoteConfig" spec="6.18.0"/>
<pod name="Firebase/InAppMessaging" spec="6.18.0"/>
<pod name="Firebase/Firestore" spec="6.18.0"/>
<pod name="Fabric" spec="1.10.2"/>
<pod name="Crashlytics" spec="3.14.0"/>
<pod name="GoogleSignIn" spec="5.0.2"/>
<pod name="GoogleTagManager" spec="7.1.2"/>
</pods>
</podspec>

Expand Down
38 changes: 38 additions & 0 deletions src/android/FirebasePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<GetTokenResult>() {
@Override
Expand Down Expand Up @@ -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
//
Expand Down
3 changes: 3 additions & 0 deletions src/ios/FirebasePlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
64 changes: 64 additions & 0 deletions src/ios/FirebasePlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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
*/
Expand Down
9 changes: 9 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions www/firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
};
Expand Down

0 comments on commit b21213f

Please sign in to comment.