Skip to content

Commit 905a539

Browse files
authored
FCM Token Listener application (#660)
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.
1 parent be6d93e commit 905a539

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/android/app/src/main/java/com/wix/reactnativenotifications/fcm/FcmToken.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,14 @@ public void onAppReady() {
7575
}
7676

7777
protected void refreshToken() {
78-
FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener( new OnSuccessListener<InstanceIdResult>() {
78+
FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener(new OnSuccessListener<InstanceIdResult>() {
7979
@Override
8080
public void onSuccess(InstanceIdResult instanceIdResult) {
8181
sToken = instanceIdResult.getToken();
82-
if(BuildConfig.DEBUG) Log.i(LOGTAG, "FCM has a new token" + "=" + sToken);
82+
if (mAppContext instanceof IFcmTokenListenerApplication) {
83+
((IFcmTokenListenerApplication) mAppContext).onNewFCMToken(sToken);
84+
}
85+
if (BuildConfig.DEBUG) Log.i(LOGTAG, "FCM has a new token" + "=" + sToken);
8386
sendTokenToJS();
8487
}
8588
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.wix.reactnativenotifications.fcm;
2+
3+
/**
4+
* API for Applications that want to listen new FCM tokens
5+
* whenever its ready.
6+
*/
7+
public interface IFcmTokenListenerApplication {
8+
void onNewFCMToken(String token);
9+
}

0 commit comments

Comments
 (0)