0

I see a lots of questions about receiving new registration id for the app when uninstall the older version and reinstalled the new version, which is an expected one.

But I came to notice that an app upgrade generates a new registration id and the old registration id is not made Invalid/NotRegistered. Sorry if I am outdated in this topic.

This causes an issue of receiving multiple notifications for the same device while notification is send from server.

So do I need to call the FirebaseInstanceId.getInstance().deleteInstanceId(); while app upgrade or does the old registration id will be invalidated in future by FCM?

AL.
  • 36,815
  • 10
  • 142
  • 281
sadiqmc
  • 171
  • 2
  • 15

2 Answers2

1

AFAIK, an App Update shouldn't generate a new registration token.

However, if you managed to receive a new token from the onTokenRefresh() callback, you should immediately update the corresponding details on your App server, saving the new and deleting the old token. This way, you don't have to call deleteInstanceId().

Unless you are receiving the new and different token just by simply calling the getToken(), in which case, this is an unintended behavior. Do post the related code snippets so that we can have a further look into it.

Community
  • 1
  • 1
AL.
  • 36,815
  • 10
  • 142
  • 281
  • well, that's what I was thinking. An app update will not update the registration id. But can update the registration id in future after some (may be more) period of time even if app is not updated. Am I right.? I have implemented the FCM in an ionic project which calls register while app launches. While app upgrade this returns a new registration id which is different from old registration id. – sadiqmc Apr 06 '17 at 07:41
  • 1
    Yes. You'll know a token is *refreshed* if `onTokenRefresh()` is triggered. There are only a few [specific scenarios](https://firebase.google.com/docs/reference/android/com/google/firebase/iid/FirebaseInstanceIdService#onTokenRefresh()) for it. What you could do is temporarily store the current token and everytime you call `getToken()`, you can compare. If the token you're getting is different, replace the old one. – AL. Apr 06 '17 at 08:04
  • yes. That would work as expected.. So I think, the possible change for refreshing token during app upgrade will be `App deletes Instance ID`. – sadiqmc Apr 06 '17 at 08:58
  • Yup. I think that would be fine. Just set the checking implementation and have the deleteInstanceId as a *fail safe*. :) – AL. Apr 06 '17 at 09:08
0

Do not store both the registration key on server database from where you are sending notification. Use Update query instead of insert registration key into database.

Amit Sharma
  • 645
  • 5
  • 13
  • Thank for reply..I know that is one scenario, but my concern was why the old registration id is not invalidated.? And your approach will affect if a user has installed the app in multiple devices and used same username in all of them. The notification will be received only to last updated registration id. – sadiqmc Apr 06 '17 at 07:31