这是保持APNS设备令牌更新的标准方法吗?

Dou*_*ith 3 cocoa-touch objective-c keychain apple-push-notifications ios

我想确保我的服务器始终具有最新的APNS设备令牌,该令牌可以在特定情况下更改.

我应该将它保存到钥匙串,并在启动时检查它是否不同,然后如果是这样更新服务器?

这是最好的方式吗?

Cha*_*lis 7

Apple实际上说不要在本地存储设备令牌.您registerForRemoteNotifications()需要设备令牌时调用.来自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.

因此,您需要做的是在启动时注册远程通知,并将该令牌发送到您的服务器.来自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.

您可以在此处找到更多文档:https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/IPhoneOSClientImp.html#//apple_ref/doc/uid/TP40008194-CH103-SW25

  • 我想补充说IMO对它进行缓存很重要.如果你对它进行缓存,那么你就会知道操作系统是否已经改变了它(非常非常非常罕见),在这种情况下,只有这样你才需要将新服务器发送到你的服务器.如果你不缓存它,那么结果将是你必须总是在你的应用程序每次运行时将令牌发送到你的服务器,并且99.999999%的时间是不必要的. (7认同)