Which apns errors should cause us to remove the tokens from our server's db?

Having some discussion about when we should clear out a token from our servers.

Docs say:

Don’t retry notification responses with the error code BadDeviceToken, DeviceTokenNotForTopic, Forbidden, ExpiredToken, Unregistered, or PayloadTooLarge. You can retry with a delay, if you get the error code TooManyRequests.

The way I see it is that with the exception of PayloadTooLarge, all other errors means you should remove the token from your server. Either because:

  • The token is no longer good
  • The token is good, but this is just not the right:
    • environment (sandbox vs production)
    • topic (the token is from a different bundle id or developer team)
    • target (app vs live activity appex)

Do I have it right?

Extra context: when using the "JSON Web Token Validator" tool, a colleague reported that a 410 -Expired token (from couple days back) was still valid today. This raises questions about when tokens should actually be deleted and how these error codes should be interpreted.


Also is it possible for the docs to get updated for us to explicitly know if a token should get removed and not leave it for interpretation?

You have it somewhat right.

BadDeviceToken could be that the token is not valid (malformed, typo, etc.) or it could be that it is a valid token in the wrong environment. A valid sandbox used in production environment will also give this error. Whether you would remove that token altogether, or somehow mark it to be used in the alternate environment is up to you, and whether you use the same database for both environments.

Similarly for DeviceTokenNotForTopic if you are managing multiple apps or multiple topics per app (for example for regular notifications and VoIP pushes), you may want to not delete the token from the database altogether, but manage the context they should be used in appropriately.

Once you get ExpiredToken or Unregistered you can safely remove the token the first time you see the error. It is possible to receive an OK response right after one of these errors due to propagation delay within the APNs infrastructure. Once you get an error that prompts to you to remove the token, you can do that and ignore the subsequent OK results.

Which apns errors should cause us to remove the tokens from our server's db?
 
 
Q