objective-c - 是否可以从 View Controller 请求 APNS 设备 token ?

标签 objective-c ios xcode push-notification

我是 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/

相关文章:

objective-c - 'instance method not found' 警告的 -Wsomething 标志是什么?

iOS 7/Xcode 5 : Access device launch images programmatically

iphone - 在 MkMapView 上隐藏、显示注释

ios - MSAL 可以与基于 swift UI 的应用程序一起使用吗?

swift - 在 cocoa 应用程序中关闭单击时显示和隐藏窗口而不是终止应用程序

iphone - 如何声明实例变量和方法在类实例之外不可见或不可用?

ios - 当我启动我的应用程序时,它会在 iPhone 应用程序屏幕上停留 4.5 秒

ios - Braintree v.zero iOS SDK 是否支持自适应支付?

ios - 用户界面测试 : Two elements w/same accessibilityTitle

objective-c - opencv 2.2 xcode4 ios4.3