如何在 iPhone 上请求设备令牌
我可以在订阅推送通知时使用 didRegisterForRemoteNotificationWithDeviceToken 回调方法来获取我的 iPhone 的设备令牌。我的问题是我以后怎样才能再次获得这个令牌?当用户订阅我的应用程序中的某些内容时,我想发送设备令牌和他们订阅的项目的 id...但我不知道从哪里获取设备令牌。我尝试使用 UIDevice 类中的 uniqueIdentifer,但该值与原始令牌不同。我想我可以在每次我的应用程序开始生成令牌时调用 registerForRemoteNotificationTypes 。但如果我这样做,我不确定如何从不同的类访问该值(我的 didRegisterForRemoteNotificationWithDeviceToken 回调位于主应用程序委托中)。感谢您对 Objective C 新手的任何帮助!
I am able to use the didRegisterForRemoteNotificationWithDeviceToken callback method to get the device token of my iphone when subscribing to push notifications. My question is how can I get this token again a later time? When a user subscribes to something in my application, I want to send the device token and the id of the item they are subscribing to...but I can't figure out where to get the device token from. I tried using the uniqueIdentifer from the UIDevice class but this value is different than what the original token was. I supposed I could call registerForRemoteNotificationTypes each time my app starts to produce the token. But if I do that, I'm not sure how I can access this value from a different class (my didRegisterForRemoteNotificationWithDeviceToken callback is located in the main application delegate). Thanks for any help for an objective C newbie!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会在您的 appDelegate 中设置一个可以从任何地方访问的属性,并将其设置为设备令牌。
然后,您可以使用以下方法在任何地方访问该令牌:
I would set a property in your appDelegate that can be accessed from anywhere, and set it to the device token.
You can then access that token anywhere by using: