iPhone registerForRemoteNotificationTypes 不会生成错误,但不会触发提供设备令牌的委托 [英] iPhone registerForRemoteNotificationTypes does not generate an error but does not fire delegate that gives device token

查看:23
本文介绍了iPhone registerForRemoteNotificationTypes 不会生成错误,但不会触发提供设备令牌的委托的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am developing an iPhone app that needs push notification. I followed the instructions for creating the certifications and modifying the app ID. I am not totally sure I did this correctly, but I did follow the directions. Any idea how I can check to see if this is OK?

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

When I ran in the emulator I did get an error message saying that the emulator did not support push notifications. This was somewhat expected.

顺便说一句:这个问题我已经问过几次了.它似乎总是与越狱的手机有关.我的手机没有越狱.

BTW: I have seem this question out there a few times. It always seems to be with a jail-broken phone. My phone is NOT jail-broken.

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

But when I debug on the iPhone the didRegisterForRemoteNotificationsWithDeviceToken method is never fired off. I will really appreciate some help. My code follows.

-(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);    
}

推荐答案

通常,如果 didRegisterForRemoteNotificationsWithDeviceToken 从未被调用,那是因为您使用的配置文件不是 APS 授权的.如果您的应用程序是生产应用程序,则必须使用分发配置文件对其进行签名才能推送工作.如果是开发应用程序,则必须使用开发配置文件对其进行签名.

Usually if didRegisterForRemoteNotificationsWithDeviceToken is never called, it is because you are using a provisioning profile that is not APS-entitled. If you app is a production app, it must be signed with a distribution profile for pushes to work. If it is a development app, you must sign it with a development profile.

还值得注意的是,provisioning profile 必须使用显式包 ID.发送到使用通配符配置文件签名的任何内容的推送将不会被传递.

It is also worthy to note that the provisioning profile must use an explicit bundle id. Pushes sent to anything signed with a wildcard profile will not be delivered.

这篇关于iPhone registerForRemoteNotificationTypes 不会生成错误,但不会触发提供设备令牌的委托的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆