为什么didRegisterForRemoteNotificationsWithDeviceToken不叫 [英] why didRegisterForRemoteNotificationsWithDeviceToken is not called

查看:206
本文介绍了为什么didRegisterForRemoteNotificationsWithDeviceToken不叫的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做我想要实现的苹果推送通知服务的应用程序。我下面的<一个给定的一步一步的指示href=\"http://mobiforge.com/developing/story/programming-apple-push-notification-services?dm_switcher=true\">this教程。

但尽管如此,该方法不会被调用。我不知道是什么原因造成的问题。谁能帮我?

   - (无效)应用:(*的UIApplication)appdidRegisterForRemoteNotificationsWithDeviceToken:(NSData的*)deviceToken {
        // * NSString的记号= [[NSString的页头] initWithData:deviceTokenencoding:NSUTF8StringEncoding];
        * NSString的海峡= [的NSString stringWithFormat:@设备令牌=%@,deviceToken]
        的NSLog(@设备令牌:%@,STR);        //的NSLog(@设备令牌被称为);
        //常量无效* devTokenBytes = [deviceToken字节]
        //的NSLog(@设备令牌);
    }     - (无效)应用:(*的UIApplication)应用didFailToRegisterForRemoteNotificationsWithError:(NSError *)错误{
        * NSString的海峡= [的NSString stringWithFormat:@错误:%@,犯错]
        的NSLog(@错误:%@,STR);
    }


解决方案

我有同样的问题:调用 registerForRemoteNotificationTypes:引用既不应用程序:didRegisterForRemoteNotificationsWithDeviceToken 也不应用程序:didFailToRegisterForRemoteNotificationsWithError:

我终于解决了与苹果公司的技术说明 TN2265 的帮助下这个问题。

这是我做过什么:

首先,我双重检查,我确实推送通知正确注册,包括验证我的调配配置文件APS-环境的关键和.app文件本身的codesigning。我拥有了一切正确设置。

然后我不得不调试推送通知状态消息在控制台(您需要在设备上安装PersistentConnectionLogging.mobileconfig供应形象和重新启动。见的 TN2265 在观察推送状态信息)。我注意到,APNS进程启动一个计时器,计算最低耐火日期,这让我怀疑推通知报名确认消息,这通常是美元,这一点psented p $,是APNS pssed苏$ P $,如图所示在TN2265:


  

重置iOS上的推送通知警报的权限


  
  

第一时间推送通知启用推应用注册,iOS的询问用户是否他们希望收到通知的应用程序。一旦用户回应此警报就不会再psented $ P $除非该设备恢复或应用程序已被卸载了至少一天。


  
  

如果要模拟你的应用程序的第一次运行,你可以离开卸载了一天的应用程序。您可以实现后者没有通过设置系统时钟向前一天或更长时间,完全关掉设备,然后重新打开该设备实际上是在等待了一天。


于是,我从设备中删除应用程序,然后手动设置中更改了iPhone的日期,重新启动设备,并重新安装应用程序。

下一次打电话给我的code registerForRemoteNotificationTypes ,它接收按预期的回调。

这解决了这个问题对我来说。希望它帮助。

I am making an application in which I want to implement apple push notification service. I am following the step-by-step instructions given in this tutorial.

But still, the methods are not called. I don't know what is causing the problem. Can anyone help me?

    - (void)application:(UIApplication *)appdidRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { 
        //NSString * token = [[NSString alloc] initWithData:deviceTokenencoding:NSUTF8StringEncoding];
        NSString *str = [NSString stringWithFormat:@"Device Token=%@",deviceToken];
        NSLog(@"Device Token:%@",str);

        //NSLog(@"Device token is called");
        //const void *devTokenBytes = [deviceToken bytes];
        //NSLog(@"Device Token");
    }

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

解决方案

I had the same issue: calling registerForRemoteNotificationTypes: invoked neither application:didRegisterForRemoteNotificationsWithDeviceToken: nor application:didFailToRegisterForRemoteNotificationsWithError:

I eventually resolved this issue with the help of Apple's technical note TN2265.

This is what I did:

First off, I double-checked that I am indeed registering correctly for Push Notifications, including verifying my provisioning profile for "aps-environment" key and the codesigning of the .app file itself. I had it all set up correctly.

I then had to debug Push Notification status messages in the console (you need to install PersistentConnectionLogging.mobileconfig provisioning profile on your device and reboot it. See TN2265 under "Observing Push Status Messages"). I noticed that apns process starts a timer and calculates a minimum fire date, which made me suspect that the Push-Notification registration confirmation message, which is normally presented at this point, is supressed by APNS, as indicated in TN2265:

Resetting the Push Notifications Permissions Alert on iOS

The first time a push-enabled app registers for push notifications, iOS asks the user if they wish to receive notifications for that app. Once the user has responded to this alert it is not presented again unless the device is restored or the app has been uninstalled for at least a day.

If you want to simulate a first-time run of your app, you can leave the app uninstalled for a day. You can achieve the latter without actually waiting a day by setting the system clock forward a day or more, turning the device off completely, then turning the device back on.

So, I removed the app from the device, then manually changed the iPhone's date in Settings, rebooted the device, and re-installed the app.

The next time my code called registerForRemoteNotificationTypes, it received callbacks as expected.

This resolved the issue for me. Hope it helps.

这篇关于为什么didRegisterForRemoteNotificationsWithDeviceToken不叫的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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