2011-10-28 55 views
0

我是新来Objective-C和iOS开发,但我想知道是否有办法从视图控制器请求苹果推送通知设备令牌,并将令牌存储在一个字符串稍后在发送的查询字符串中使用到我的web应用程序。是否可以从View Controler请求APNS设备令牌?

我一直在寻找,但一直没能找到解决办法。任何帮助,将不胜感激!

回答

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 
+0

与smalltalk环境中的回调非常相似。詹姆斯的建议很有道理。 – mozillanerd

+0

这听起来是对的。我目前有: - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken NSLog(@“didRegisterForRemoteNotificationsWithDeviceToken:%@”,deviceToken); } 在AppDelegate中。语法是什么从视图控制器调用registerForRemoteNotificationTypes? – Kevin

+0

这取决于您想要注册的通知类型。我已经添加到我的答案。 –