Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is this the standard way for keeping APNS device token updated?

I want to make sure my server always has the up to date APNS device token, which can change under specific circumstances.

Should I save it to the Keychain, and on launch check if it's different, and then update the server if so?

Is that the best way to be doing this?

like image 240
Doug Smith Avatar asked Sep 15 '25 18:09

Doug Smith


1 Answers

Apple actually say NOT to store the device token locally. You call registerForRemoteNotifications() when you need the device token. From Apple:

Never cache a device token; always get the token from the system whenever you need it. If your app previously registered for remote notifications, calling the registerForRemoteNotifications method again does not incur any additional overhead, and iOS returns the existing device token to your app delegate immediately. In addition, iOS calls your delegate method any time the device token changes, not just in response to your app registering or re-registering.

So what you need to do is register for remote notifications on launch, and send that token to your server. From Apple: Device tokens can change, so your app needs to reregister every time it is launched and pass the received token back to your server.

You can find more documentation here: https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/IPhoneOSClientImp.html#//apple_ref/doc/uid/TP40008194-CH103-SW25

like image 82
Chandler De Angelis Avatar answered Sep 17 '25 08:09

Chandler De Angelis