1

我已经实现了以下代码但没有获得设备令牌?

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    NSLog(@"deviceToken: %@", deviceToken);
}
4

3 回答 3

4

If you don't already, you should have a call to registerForRemoteNotificationTypes in your didFinishLaunchingWithOptions. Something along the lines of:

[[UIApplication sharedApplication]
     registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
                                         UIRemoteNotificationTypeSound |
                                         UIRemoteNotificationTypeAlert)];

You should also have a didFailToRegisterForRemoteNotificationsWithError method that gets called if registration fails. The NSerror it gets should tell you more about why it might be failing.

于 2009-09-02T19:43:35.837 回答
1

你在模拟器里面试试吗?推送通知和相关的 appdelagate 事件在模拟器上不起作用。

如果您正在使用该设备,请确保您的应用程序的捆绑标识符必须与您在 iphone privisioning protal 上创建 AppID 时定义的推送 ssl 捆绑标识符相同。

于 2010-08-13T08:35:44.287 回答
0

要使用 APNs 注册您的设备,您首先必须调用

    [[UIApplication sharedApplication]
 registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];

这通常写在您的 AppDelegate 中(在 didFinishLaunching 中)。然后确保您已实施

didRegisterForRemoteNotificationsWithDeviceToken 

它为您提供设备令牌和

didFailToRegisterForRemoteNotificationsWithError

这会给您代码可能遇到的错误。

于 2013-02-21T03:24:51.493 回答