EddyVerbruggen / nativescript-plugin-firebase

:fire: NativeScript plugin for Firebase
https://firebase.google.com
MIT License
1.01k stars 448 forks source link

Equivalent callback for native `onNewToken` #1793

Open matthew798 opened 3 years ago

matthew798 commented 3 years ago

The onPushTokenReceivedCallback fires all the time, regardless of whether an existing token or a new token is "received". Is there a way to check if a new token is received?

In the native api docs for android, there is the onNewToken callback:

/**
 * There are two scenarios when onNewToken is called:
 * 1) When a new token is generated on initial app startup
 * 2) Whenever an existing token is changed
 * Under #2, there are three scenarios when the existing token is changed:
 * A) App is restored to a new device
 * B) User uninstalls/reinstalls the app
 * C) User clears app data
 */
@Override
public void onNewToken(String token) {
    Log.d(TAG, "Refreshed token: " + token);

    // If you want to send messages to this application instance or
    // manage this apps subscriptions on the server side, send the
    // FCM registration token to your app server.
    sendRegistrationToServer(token);
}

As you can see, this callback is ideal for updating a token on a backend server as it will only generate a request if the token has changed. Is there an equivalent callback in this plugin?