iPhone设备令牌:它可以存储在iPhone上吗?

发布于 2024-09-09 00:29:46 字数 370 浏览 0 评论 0 原文

我必须开发一个以特定方式使用推送通知的应用程序,我有一个非常棘手的问题:设备令牌可以本地存储在应用程序沙箱中吗? 原因如下:这个应用程序应该实现一个通知系统,允许用户仅从 iPhone 订阅某些特定事件。 因此,要做到这一点,我需要在应用程序运行时随时将 iPhone 的设备令牌发送到我的数据库,从我得到的情况来看,设备令牌仅在调用时才可用,

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken

对吗? 或者以后有什么办法可以检索到这些信息吗?

谢谢。

I have to developp an app that uses Push Notification in a particular way, and I had a pretty tricky question : can the device token be stored locally in the app sandbox?
Here's the why : this app should implement a notification system that allows the user to subscribe for some particular events only, from the iphone.
So to do so, I need to send to my database the Device Token of the iPhone at any time when the app is running, and from what I get, the device token is only avaliable when the

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken

is called right?
Or is there any way to retrieve this information later?

Thanks.

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

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

发布评论

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

评论(2

无名指的心愿 2024-09-16 00:29:46

推送通知编程指南 但是建议您不要在本地存储令牌:

“应用程序应在每次启动时进行注册,并向其提供程序提供当前令牌。它会调用 registerForRemoteNotificationTypes: 来启动注册过程。”

……

“通过在每次应用程序启动时请求设备令牌并将其传递给提供商,您可以帮助确保提供商拥有该设备的当前令牌。如果用户将备份恢复到该设备以外的设备,创建备份的目的(例如,用户将数据迁移到新设备),如果用户将备份数据恢复到新设备或重新安装操作,则他或她必须至少启动一次应用程序才能再次接收通知。此外,如果您的应用程序永远不要缓存设备令牌并将其提供给您的提供商,始终从系统获取令牌。之前已注册,调用 registerForRemoteNotificationTypes: 会导致 iOS 立即将设备令牌传递给委托,而不会产生额外的开销。”


The push notification programming guide however recommends you not to store the token locally:

"An application should register every time it launches and give its provider the current token. It calls registerForRemoteNotificationTypes: to kick off the registration process."

"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. If a user restores a backup to a device other than the one that the backup was created for (for example, the user migrates data to a new device), he or she must launch the application at least once for it to receive notifications again. If the user restores backup data to a new device or reinstalls the operating system, the device token changes. Moreover, never cache a device token and give that to your provider; always get the token from the system whenever you need it. If your application has previously registered, calling registerForRemoteNotificationTypes: results in iOS passing the device token to the delegate immediately without incurring additional overhead."

夜未央樱花落 2024-09-16 00:29:46

您应该将其存储在手机上的某个位置。 NSUserDefaults 是一个不错的地方,因为它不是很大的数据,并且您可以在之后轻松检索它。我还建议将其保存在您的服务器上,并且仅在令牌更改时更新它。

You should store it somewhere on the phone. NSUserDefaults is a decent place to do it since it's not a big piece of data and you can retrieve it easily afterwards. I would also recommend saving it on your server, and only updating it if the token changes.

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