What happens if the APNS device token is out of date?

According to this forum post Can APNS device tokens ever change? The device token may expire or APNS may change the device token. My question is, will APNS use the expired token for notification if the server sends this expired token to Apple? Can APNS use this expired token for another device?

+6
source share
1 answer

I have never encountered an expired device token, so I can not tell you about my personal experience. I also can not tell you from the Apple APNS documentation, because they do not answer your question (and I read all their APNS documents more than once).

Your application and your server should be able to handle the expiration of the device token no matter what the answer is to your question.

  • Always call registerForRemoteNotificationTypes when starting your application and send the device token to the server if it differs from the last token of your application on this device.

  • Assign another unique identifier on your server for each device using your application. Ask the application to send this identifier to your server along with the device token. Thus, if the device token changes, your server will know its new device token for the existing device, and not the new device on which your application was installed.

  • After # 1 and # 2, make sure that your server will have the current device token for each device that recently launched your application (on devices where your application has not been recently launched, users probably donโ€™t care about their application, so I'm not sure if sending them push notifications will make any difference).

  • If you send a notification to the old device token, if it works, all is well. If this is not the case, you will either receive an โ€œInvalid Tokenโ€ error message, or you will receive this device token in the Feedback service. In either of these two cases, you must stop sending notifications to this token.

  • I assume that APNS will not reuse the expired token for another device, but if this happens, your server can identify it using the unique identifier suggested in # 2. In this case, make sure that your server only assigns the device token to another device.

+10
source

Source: https://habr.com/ru/post/957402/


All Articles