iOS 推送通知 - 如何处理设备 ID?
最常用的策略是什么? 我现在正在尝试实现以下功能:
在应用程序启动时:
- 从某些本地存储获取以前保存的设备 ID
- 获取设备 ID
- 如果更改,保存新 ID,将更新发送到服务器
这是正确的方法吗? 在本地存储设备 ID 的最佳方式是什么?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最佳实践是每次应用程序启动时将推送设备令牌(与 Serg Shiyan 提到的 uniqueIdentifier 不同)发送给 Apple。这会让 Apple 知道您的应用程序仍然处于活动状态。
请参阅注册远程推送通知:
来自本地和推送通知编程指南
根据我的经验,推送令牌有很多原因可能会被宣告无效。其中包括应用程序卸载和混合具有不同证书的应用程序(开发、针对沙箱/实时推送服务器的临时运行)。按照建议,每次启动时都会发送令牌,这将为您节省一些调试时间。
因此,基本上没有理由在应用程序运行时将推送令牌存储在内存中。您只需在应用程序下次启动时请求一个新的(可能是同一个)。
Best practice is to send the push device token (not the same as the uniqueIdentifier mentioned by Serg Shiyan) to Apple every time the app starts. This will let Apple know your app is still active.
See registering for remote push notifications:
from the Local and Push notifications Programming guide
In my experience there are a number of reasons why push tokens might be invalidated. These include app deinstalls and mixing apps with different certificates (dev, ad-hoc running against sandbox / live push servers). It will save you some debugging by sending the token on start each time as recommended.
So basically there is no reason to store the push token other than in memory while your app is running. You just request a new one (possibly the same one) the next time your app starts.
“基于各种硬件详细信息,每个设备唯一的字母数字字符串。(只读)(在 iOS 5.0 中已弃用。相反,请创建特定于您的应用程序的唯一标识符。)
特殊注意事项
不要使用 uniqueIdentifier 属性。要创建特定于您的应用的唯一标识符,您可以调用
CFUUIDCreate
函数来创建 UUID,并使用NSUserDefaults
类将其写入默认数据库。”(Apple公司)"An alphanumeric string unique to each device based on various hardware details. (read-only) (Deprecated in iOS 5.0. Instead, create a unique identifier specific to your app.)
Special Considerations
Do not use the uniqueIdentifier property. To create a unique identifier specific to your app, you can call the
CFUUIDCreate
function to create a UUID, and write it to the defaults database using theNSUserDefaults
class." (Apple Inc)