Skip to content

Commit

Permalink
FCM Token Listener application (#660)
Browse files Browse the repository at this point in the history
Sometimes we need to use the FCM token, sync with server and more.
Today the token is sent to the JS, that prevents us from making custom native logic that deals with FCM token.

Changes done as small as possible, it is optional, Instance of Application class can implement the interface in order to receive the token itself to the native side.
  • Loading branch information
swabbass authored Aug 6, 2020
1 parent be6d93e commit 905a539
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,14 @@ public void onAppReady() {
}

protected void refreshToken() {
FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener( new OnSuccessListener<InstanceIdResult>() {
FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener(new OnSuccessListener<InstanceIdResult>() {
@Override
public void onSuccess(InstanceIdResult instanceIdResult) {
sToken = instanceIdResult.getToken();
if(BuildConfig.DEBUG) Log.i(LOGTAG, "FCM has a new token" + "=" + sToken);
if (mAppContext instanceof IFcmTokenListenerApplication) {
((IFcmTokenListenerApplication) mAppContext).onNewFCMToken(sToken);
}
if (BuildConfig.DEBUG) Log.i(LOGTAG, "FCM has a new token" + "=" + sToken);
sendTokenToJS();
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.wix.reactnativenotifications.fcm;

/**
* API for Applications that want to listen new FCM tokens
* whenever its ready.
*/
public interface IFcmTokenListenerApplication {
void onNewFCMToken(String token);
}

0 comments on commit 905a539

Please sign in to comment.