Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What Happen If a APNS Device Token Expired?

According to this forum post Does the APNS device token ever change, once created? The device token might be expire or APNS might change the device token. My question is that whether the APNS will use the expired token for notification if the server send this expired token to Apple? Can APNS use this expired token for another device?

like image 767
Imran Qadir Baksh - Baloch Avatar asked Nov 05 '13 05:11

Imran Qadir Baksh - Baloch


People also ask

What happens when your token expires?

When a token has expired or has been revoked, it can no longer be used to authenticate Git and API requests. It is not possible to restore an expired or revoked token, you or the application will need to create a new token.

What will be the device behavior if APNs gets expired?

If the APNS certificate expires, users can no longer enroll devices.

Do APNs tokens expire?

APNs certificates expire annually, so a new certificate must be uploaded to Airship every year upon renewal. This process can take a lot of time if you have multiple Airship projects, and you cannot send messages to your iOS users if your certificate is expired.


1 Answers

I've never encountered an expired device token, so I can't tell you from my personal experience. Nor can I tell you from Apple's APNS documentation, because they don't answer your question (and I read all their APNS docs more than once).

Your app and your server should be able to handle device token expiration regardless to what the answer to your question is.

  1. Always call registerForRemoteNotificationTypes when your app is launched, and send the device token to the server if it's different than the last device token your app got on that device.

  2. Assign in your server another unique identifier for each device that uses your app. Have the app send that identifier to your server along with the device token. This way, if the device token changes, your server will know it's a new device token for an existing device and not a new device where your app was installed.

  3. Following #1 and #2 will ensure that your server will have the current device token for each device on which your app was launched recently (on devices where your app wasn't launched recently, the users probably don't care much about your app, so I'm not sure that sending them push notifications will make any difference).

  4. If you do send a notification to an old device token, if it works, all is good. If it doesn't, you'd either get an Invalid Token error response or you'd get that device token in the Feedback service. In either of those two cases, you should stop sending notifications to that token.

  5. I assume APNS won't reuse an expired token for another device, but if it does, your server can identify it by using the unique identifier I suggested in #2. In that case, make sure your server assigns the device token only to the other device.

like image 62
Eran Avatar answered Sep 29 '22 21:09

Eran