2

We have an iOS React Native app that receives FCM notifications from a Firebase server via react-native-firebase.

We get the "messaging token" on user login, then we save it to our firebase database, and that token is then used to send FCM notifications to that user. As the user logs out, the token is invalidated.

However, if the user uninstalls the app, we have no way to invalidate the token. When they reinstall, they are logged out, but they continue to receive notifications for the app.

Is there a way to invalidate the messaging token? And if not, how do I stop the FCM notifications for a previous installation from arriving?

KENdi
  • 7,576
  • 2
  • 16
  • 31
deworde
  • 2,679
  • 5
  • 32
  • 60
  • We use a `lastseen` timestamp for each device *and* (for our app at least) the FCM messages are scheduled by the client. If the messages are generated server side, then you'll have to include some throttling. Add a `sent_counter` and increment it in the device's profile every time you send it a message. When the device comes back online, make it zero out this counter. Base your throttling on the `sent_counter` and `lastseen`. Create a cron job that runs once a week that: *1) schedules re-engagement campaign after 3 months* **and** *2) prunes devices older than 6 months.* – James Poag Oct 03 '18 at 11:32
  • @jamespoag This seems like an answer more than a comment, thanks! – deworde Oct 03 '18 at 11:35

1 Answers1

1

When an app is deleted and re-installed, it must ask again for permission before sending notifications. Therefore, no notifications will be received before opening the app again for the first time. This means that your app must be asking for and getting permission to show notifications prior to checking if there is a user logged in. I suggest you try a couple different things:

  • Verify a user is logged in before asking permission to send notifications, or
  • Upon launching app, check for a logged in user. If no user is found, delete any registration tokens
Jen Person
  • 7,356
  • 22
  • 30
  • Thanks Jen. Looking at it more closely, it's very odd, but after uninstalling and re-installing, the "onAuthStateChanged" and "onTokenRefresh" handlers appear to trigger on connection with the values that they had when uninstalled. – deworde Oct 22 '18 at 13:28
  • Ah-hah! https://stackoverflow.com/q/27893418/14250 – deworde Oct 22 '18 at 14:47