小编Ric*_*ker的帖子

iPhone registerForRemoteNotificationTypes不会生成错误,但不会触发提供设备令牌的委托

我正在开发一个需要推送通知的iPhone应用程序.我按照说明创建了认证并修改了应用ID.我并不完全确定我这样做是正确的,但我的确遵循了指示.知道如何检查这是否正常?

当我在模拟器中运行时,我收到一条错误消息,指出模拟器不支持推送通知.这有点预期.

顺便说一下:我有几次看似这个问题.它总是似乎是一个破牢的手机.我的手机没有被囚禁.

但是当我在iPhone上调试时,didRegisterForRemoteNotificationsWithDeviceToken方法永远不会被触发.我真的很感激一些帮助.我的代码如下.

-(void)applicationDidFinishLaunching:(UIApplication *)application 
{    
   rootController.delegate = self;
   [window addSubview:rootController.view];
   [window makeKeyAndVisible];

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

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

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

iphone apple-push-notifications devicetoken ios appdelegate

17
推荐指数
3
解决办法
2万
查看次数