我是 Objective-C 和 iOS 开发的新手,但我想知道是否有一种方法可以从 View Controller 请求 Apple 推送通知设备 token 并将 token 存储在一个字符串中,以便稍后在查询字符串中使用发送到我的网络应用程序。
我一直在寻找,但未能找到解决方案。任何帮助将不胜感激!
最佳答案
您应该能够在代码中的任何位置调用 registerForRemoteNotificationTypes:
。
但是您必须在您的应用委托(delegate)中实现application:didRegisterForRemoteNotificationsWithDeviceToken:
。
您最多可以注册 3 种不同类型的通知。只需根据需要删除和添加。
[[UIApplication sharedApplication]
registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeAlert | //Alerts are pop up boxes or on ios5, banners
UIRemoteNotificationTypeBadge | //Badges are the little red number on the icon
UIRemoteNotificationTypeSound)]; //Sounds are... well, sounds. These can be played when presenting a remote notification
关于objective-c - 是否可以从 View Controller 请求 APNS 设备 token ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7933720/