question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Deleting the Instance ID token does not trigger onNewToken

See original GitHub issue

[READ] Step 1: Are you in the right place?

Yes

[REQUIRED] Step 2: Describe your environment

  • Android Studio version: 4.1.1
  • Firebase Component: Messaging
  • Component version: 21.0.1

[REQUIRED] Step 3: Describe the problem

Inconsistency between iOS and Android SDKs when a token is deleted. On iOS, there was an update to the SDK to make sure the listener refreshed, please see p/r https://github.com/firebase/firebase-ios-sdk/pull/5339. Unable to reproduce same behaviour on Android.

Steps to reproduce:

  1. get Firebase Messaging Token FirebaseInstanceId.getInstance().getToken();
  2. delete Firebase Messaging Token FirebaseInstanceId.getInstanceId().deleteInstanceId()
  3. get Firebase Messaging Token FirebaseInstanceId.getInstance().getToken();

Token is updated, but FirebaseMessagingService onNewToken is not triggered, unlike on iOS.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ciarandcommented, Apr 1, 2021

I’ve put together a fix for this (internal ref 365888536) and it should be rolling out in the next FCM release.

But, I’ve seen that FirebaseInstanceId is deprecated, and that either FirebaseMessaging.getToken() or FirebaseInstallations.getToken(boolean forceRefresh) should be used instead, taken from the docs:

Yes, in general the future is to go through either FirebaseInstallations (for IDs) or FirebaseMessaging (for FCM registration tokens). The FirebaseInstallations.getToken method returns an installations auth token, which is distinct from the FCM registration token. For sending an FCM message to an app instance, the FirebaseMessaging.getToken method is the right one to use.

0reactions
mikehardycommented, Apr 14, 2021

@ciarand great! @helenaford note this is packaged in firebase-android-sdk 27.0.0 which is a breaking change for react-native-firebase and we haven’t ported yet 😅 https://github.com/invertase/react-native-firebase/issues/5150

I believe based on BoM comparision if you are not using the admob module that you can overrde the sdk and everything will be fine but it’s untested as of yet

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I trigger manually a Firebase onNewToken call?
First of all you need to delete old instance id and after that, get id using FirebaseInstanceId.getInstance().getInstanceId(); . Example:
Read more >
FirebaseMessagingService. onNewToken() method is called ...
onNewToken () method is called even though token is not changed after ... The app deletes Instance ID; The app is restored on...
Read more >
Best practices for FCM registration token management
In addition to removing tokens in obvious cases of invalid token responses, ... Determining whether a token is fresh or stale is not...
Read more >
Obtaining and Deleting a Push Token-Basic Capabilities ...
If no token is returned by getToken, the onNewToken method can be used to obtain one. ... Therefore, the token will not be...
Read more >
Remote Notifications with Firebase Cloud Messaging - Xamarin
FCM notifications overview; Requirements; Start an app project ... If you do not see an instance ID token, add the following line to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found