模拟器上的设备令牌请求没有响应

Sar*_*rah 0 push-notification apple-push-notifications ios ios-simulator

我是 iphone 技术的新手,现在我正在使用一个需要实现推送通知的应用程序。

我按照链接:

http://mobiforge.com/developing/story/programming-apple-push-notification-services#comment-7850

另外,使用了以下代码:

 NSLog(@"Registering for push notifications...");
    [[UIApplication sharedApplication]
  registerForRemoteNotificationTypes:
 (UIRemoteNotificationTypeAlert |
  UIRemoteNotificationTypeBadge | 
  UIRemoteNotificationTypeSound)];

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken 
{
    NSString *str = [NSString stringWithFormat:@"Device Token=%@",deviceToken];
    NSLog(str);
}

- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err 
{ 
    NSString *str = [NSString stringWithFormat: @"Error: %@", err];
    NSLog(str);    
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 
{
    for (id key in userInfo) 
 {
        NSLog(@"key: %@, value: %@", key, [userInfo objectForKey:key]);
    }    
}
Run Code Online (Sandbox Code Playgroud)

事情是,当我运行程序时,我应该根据代码在调试器窗口中获取设备令牌,而不是我收到如下错误:

" 注册错误。错误:Error Domain=NSCocoaErrorDomain Code=3010 "模拟器不支持远程通知" UserInfo=0x6e055a0 {NSLocalizedDescription=模拟器不支持远程通知} "

我应该如何解决这个问题?

请帮帮我。

谢谢你。

Bea*_*ker 5

因为模拟器不支持它......在示例中它在控制台中显示设备标识符。控制台正在显示来自设备的反馈。获取信息的不是控制台,而是发回信息的设备。因此,仅仅因为控制台在您的 Mac 上显示信息并不意味着您的 Mac 能够直接获取该信息。有时它必须由设备发送。尝试在设备上运行它。