ios8下的远程推送通知

来源:互联网 发布:广州少年编程培训班 编辑:程序博客网 时间:2024/05/17 02:04

       今天将项目适配IOS8,但是推送通知注册设备获得设备标识的几个代理方法一直没有执行。didRegisterForRemoteNotificationsWithDeviceToken   和   didFailToRegisterForRemoteNotificationsWithError 。即如下的方法没有被执行。


       后来查了一下UIApplication (UIRemoteNotifications)远程推送这个类的API ,发现IOS8下新增了一个API  registerForRemoteNotifications

       即原来的设置推送类型方法 registerForRemoteNotificationTypes:(UIRemoteNotificationType)types 在ios8下被弃用了。代替这个方法的是 registerForRemoteNotifications 和 - (void)registerUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings 。第一个方法是启用远程推送通知。第二个方法是设置推送通知的类型,比如显示一个alert或者banner、在应用icon上提示一个新到消息数、播放一段声音。

       ios8以前的远程推送通知的流程是这样的,苹果官方建议在应用启动的时候,调用 registerForRemoteNotificationTypes:(UIRemoteNotificationType)types 方法向苹果服务器注册ios设备,申请设备标识devicetoken,同时设置推送通知的类型。

        但是到了ios8,苹果好像对这个远程推送做了开关限制。即在应用启动的时候必须调用 registerForRemoteNotifications 方法启用推送通知。系统才会向苹果注册和获取标识。


         并且通过 - (void)registerUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings 设置推送通知的类型 。如下



      系统在接收到远程推送通知的时候,调用方法 - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 方法处理接受推送消息。



0 0
原创粉丝点击