When does the Expo Push Notification service return DeviceNotRegistered (besides the obvious)?

Obviously, the Expo push notification endpoint will return a DeviceNotRegistered error code if you send a push notification token that isn’t actually registered with the service. My question is, are there any scenarios were a token would previously be registered and then become unregistered? Like, does Expo clean up their tokens if one of the platform-specific services reports that that token is no longer valid?

The interface is: when you get back a DeviceNotRegistered error for a token, you should stop sending messages to that token.

The reasons for getting DeviceNotRegistered could include:

  • Not asking the user for permission to send notifications
  • Sending a malformed or bogus token
  • Apple’s sending back “Unregistered” as the error reason from APNs. There are many reasons this happens e.g. they cycle tokens, the user could turn off notifications, etc. Completely up to Apple’s discretion; Expo reports that back as “DeviceNotRegistered”.
  • Similar for Google (GCM and Amazon SNS).
  • In the future, it is likely that Expo will remove tokens from our database or mark them as unregistered if Apple or Google reports them as unregistered. This is an implementation detail and is not intended to affect anything developer-facing – it’s just a way to reduce pointless requests to Apple and Google.
  • Expo may also expose a way for (non-developer) users to disable / re-enable notifications on a per-project basis, and we might send back DeviceNotRegistered in that case too. From a developer’s perspective, this is the same as Apple or Google saying that a device token is no longer registered and won’t require code changes.

So yes it is possible and expected for a previously registered token to become unregistered at the discretion of the push services.

I’m noticing many of my user’s push tokens have started to return “DeviceNotRegistered”. Should we be somehow routinely updating a user’s push token? i.e. Should we do something where like every time they start the app, we get push token and send it to our backend?

This is what we do. We basically do the workflow described in the example here (https://docs.expo.io/versions/latest/guides/push-notifications#__next) every time the app loads (if the user is logged in). Usually the token is the same, so our backend just overwrites it, but sometimes it changes so then we’re prepared. When we send out notifications, we send out to all push tokens matching that user. And when the push comes back with DeviceNotRegistered, we remove it from our database so its not sent out the next time (then the list actually gets smaller sometimes).

1 Like

Thank yo llamaluvr. That makes sense. I think we will implement the same.

Sorry if is not obvious for me, but, how to workarround this problem? We have expired or “DeviceNotRegistered” error, but expo (in client) not returning a new Expo Token.