是否可以从View Controller请求APNS设备令牌?

时间:2011-10-28 19:10:19

标签: objective-c ios xcode push-notification

我是Objective-C和iOS开发的新手,但我想知道是否有办法从View Controller请求Apple推送通知设备令牌并将令牌存储在字符串中以便稍后在查询字符串中使用发送到我的网络应用程序。

我一直在寻找,但未能找到解决方案。任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:4)

您应该可以在代码中的任何位置拨打registerForRemoteNotificationTypes:

但您必须在应用代理中实施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