Push token changed after which event


#1

Hi all,

does anybody know after which event the push token of a device is changed?
After a store app update?

Thanks,
Ben


#2

I’m curious too. When I delete and reinstall the Expo client I noticed my pushtoken changed, the old pushtoken seems to stay connected to my device since some of the users receive a single notification more than one time.

I also found Notifications.getDevicePushTokenAsync(); is available for standalone apps, does this token behave like a regular APNS/GCM token?


#3

@ide can you explain in some more detail how this all works?


#4

With a Expo, the Expo push token never changes for as long as an app is installed. If the user uninstalls and reinstalls an app they will get a new Expo push token. On Android, if they clear the app’s data they will get a new Expo push token.

The Expo client sends the Expo push token and the native device token to the Expo servers. The native device token can change at any time the app is launched; different versions of iOS have different behavior for when to refresh the device token. Apple does not document the specific behavior and I don’t think Google does either.

On iOS (this may have changed in 11 though — it’s not documented) it is possible for one app to have two valid device tokens according to some Stack Overflow posts. This means in a traditional iOS app, the user could receive double notifications. Usually the layer of indirection from the Expo push token prevents this but not in the case when a user gets a new Expo push token (described above).


ExponentPushToken - When does it really change?
#5

Thanks for your detailed and helpful answer! I guess there is no fool proof solution to make sure a device registers only once then… :thinking:


#7

@ide Hi, in my production environment I notice that most users have more than one token ( some have 50 ), also I have the case when users don’t receive any notifications although notification API return status ok for all his push tokens, I notice that happen when user have many push token (more 10), can you recommend me what should I do in this situation? Maybe i should bind token not only for the user and for user/deviceID, could this help me?


#8

A user should not have more than one Expo push token unless they clear their app data or uninstall and re-install the app. The Expo push token is otherwise consistent.

For notifications that return “ok” – you must check both the result of the send endpoint and the getReceipts endpoint. “ok” in the push ticket from sending means that Expo received the notification, while “ok” in the asynchronous push receipt means that Apple/Google received the notification.


#9

@ide

  1. On every app launch, I run Notifications.getExpoPushTokenAsync and send to the backend token, backend store token by unique userId/token
  2. Yes, I check, I am using expo-server-sdk-node (3.0.1), sometimes I get DeviceNotRegistered and delete this user/token, but anyway, some users still have more than one token and all them got status ok from getReceipts endpoint

Also, i notice users that have more one token have the devices iPhone 5,6


#10
  1. If you are seeing different Expo push tokens, the most likely explanation is that the user re-installed the app, logged in with another device, or cleared their app data through some other means.
  2. If the getReceipts endpoint is returning “ok”, that means Apple/Google received the notification successfully. It doesn’t necessarily mean the device received the notification (e.g., the user may have uninstalled the app or revoked the remote-notification permissions). If your notification payload is correctly formatted, I don’t think there is anything more you can do in this scenario; Apple acknowledged successful receipt of the notification so your push credentials were correct and the push notification payload was not too large.