iOS 推送通知 - 如何处理设备 ID?

发布于 2024-12-29 02:20:39 字数 178 浏览 4 评论 0 原文

最常用的策略是什么? 我现在正在尝试实现以下功能:

在应用程序启动时:

  • 从某些本地存储获取以前保存的设备 ID
  • 获取设备 ID
  • 如果更改,保存新 ID,将更新发送到服务器

这是正确的方法吗? 在本地存储设备 ID 的最佳方式是什么?

What is most commonly used strategy?
I'm trying now to implement following:

On application start:

  • Get previously saved device Id from some local storage
  • Get device Id
  • If changed, save new Id, send update to server

Is this right approach?
What is the best way to store device Id locally?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

天涯离梦残月幽梦 2025-01-05 02:20:39

最佳实践是每次应用程序启动时将推送设备令牌(与 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:

By requesting the device token and passing it to the provider every time your application launches, you help to ensure that the provider has the current token for the device.

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.

简单气质女生网名 2025-01-05 02:20:39

“基于各种硬件详细信息,每个设备唯一的字母数字字符串。(只读)(在 iOS 5.0 中已弃用。相反,请创建特定于您的应用程序的唯一标识符。)

@property (nonatomic, readonly, retain) NSString *uniqueIdentifier

特殊注意事项
不要使用 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.)

@property (nonatomic, readonly, retain) NSString *uniqueIdentifier

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 the NSUserDefaults class." (Apple Inc)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文