2

I am using Ionic and Firebase with cloud function. Whenever data is updated I am sending notification.

I have two type of users: members and non-member.

For members when they signup/login, if users signup I generate FCM token and store it. If users login I check if the user has a device token stored.

Now if I also want to send push notification for non-members I also need to store their device token.

How do I go about this?

I have read that the token updates once in a while? If that's the case how can I check ?

KENdi
  • 7,576
  • 2
  • 16
  • 31
Manas
  • 3,060
  • 4
  • 27
  • 55

1 Answers1

2

I don't know which cordova-plugin you are using for firebase. But most of them provide a callback method which gets called when the firebase-sdk receives a new token. For example the onTokenRefresh method of cordova-plugin-firebase. When the callback is invoked you send the new token to your server.

David
  • 7,387
  • 3
  • 22
  • 39
  • thxx for your reply. I am using "fcm plugin" yes there is this onTokenRefresh method. I am a little confused about this. there will be a new token created in the ontokenrefresh method when user uninstalls and re-install the app right? – Manas Aug 07 '17 at 15:16
  • i just want to know. for the same device when the onTokenRefresh is called will the newly generated token will be same as the old one from the same device? – Manas Aug 07 '17 at 15:55
  • I think following answer also answers your question: https://stackoverflow.com/a/37686075/6184203. The initial token is generated when you first start your app and it can connect to the google-servers, after that the token may change (refresh) sometimes and onTokenRefresh will be called with the new (different) token. – David Aug 07 '17 at 16:17