zoukankan      html  css  js  c++  java
  • iOS8推送消息的回复处理速度

         iOS8我们有一个新的通知中心,我们有一个新的通报机制。当在屏幕的顶部仅需要接收一个推拉向下,你可以看到高速接口,天赋并不需要输入应用程序的操作。锁定屏幕,用于高速处理可以推动项目。

    推送信息,再次提高处理效率。

         可以进行直接互动的短信、邮件、日历、提醒,第三方应用,可以让你不用进入程序就能进行快捷操作,并专注于手中正在做的事情。

    •  在通知横幅高速回复信息,不用进入短信程序;
    •  可直接拒绝或接受邮件邀请;
    •  可对提醒进行标记为完毕或推迟;
    •  当第三方应用更新接口后便可直接相应用进行高速操作。

                             消息回复                 消息快捷回复

         近期研究了下iOS8的官方文档。对这项功能进行了钻研,基本上效果已经出来。由于远程消息推送比較繁琐,须要后台支持,所以我用本地推送来取代的,基本上它们要调用的代理方法类似。

    长话短说,以下我就说下主要的流程:

    1.创建消息上面要加入的动作(button的形式显示出来)  

     UIMutableUserNotificationAction *action = [[UIMutableUserNotificationAction alloc] init];
        action.identifier = @"action";//button的标示
        action.title=@"Accept";//button的标题
        action.activationMode = UIUserNotificationActivationModeForeground;//当点击的时候启动程序
        //    action.authenticationRequired = YES;
        //    action.destructive = YES;
    
        UIMutableUserNotificationAction *action2 = [[UIMutableUserNotificationAction alloc] init];  //第二button
        action2.identifier = @"action2";
        action2.title=@"Reject";
        action2.activationMode = UIUserNotificationActivationModeBackground;//当点击的时候不启动程序。在后台处理
        action.authenticationRequired = YES;//须要解锁才干处理,假设action.activationMode = UIUserNotificationActivationModeForeground;则这个属性被忽略;
        action.destructive = YES;

    2.创建动作(button)的类别集合

    UIMutableUserNotificationCategory *categorys = [[UIMutableUserNotificationCategory alloc] init];
        categorys.identifier = @"alert";//这组动作的唯一标示
        [categorys setActions:@[action,action2] forContext:(UIUserNotificationActionContextMinimal)];

    3.创建UIUserNotificationSettings,并设置消息的显示类类型
     UIUserNotificationSettings *uns = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound) categories:[NSSet setWithObjects:categorys, nil]];

    4.注冊推送

      
    [[UIApplication sharedApplication] registerUserNotificationSettings:uns];
    <pre name="code" class="objc">[[UIApplication sharedApplication] registerForRemoteNotifications];

    
    

    UserRequires call to registerUserNotificationSettings:• SilentInfo.plist UIBackgroundModes array contains remote-notification•
Can use both

    离线push数据包带上特定Category字段(字段内容需要前后台一起定义。必需要保持一致),手机端收到时。就能展示上述代码相应Category设置的button,和响应button事件。

    // payload example:  {"aps":{"alert":"Incoming call", "sound":"default", "badge": 1, "category":"incomingCall"}}

    重大改动: 离线push数据包之前能带的数据最多为256字节,如今APPLE将该数值放大到2KB

    这个应该是仅仅针对IOS8的。

    5.发起本地推送消息

     UILocalNotification *notification = [[UILocalNotification alloc] init];
        notification.fireDate=[NSDate dateWithTimeIntervalSinceNow:5];
        notification.timeZone=[NSTimeZone defaultTimeZone];
        notification.alertBody=@"測试推送的快捷回复";
        notification.category = @"alert";
        [[UIApplication sharedApplication]  scheduleLocalNotification:notification];
        
        //用这两个方法推断是否注冊成功
        // NSLog(@"currentUserNotificationSettings = %@",[[UIApplication sharedApplication] currentUserNotificationSettings]);
        //[[UIApplication sharedApplication] isRegisteredForRemoteNotifications];

    6.在AppDelegate.m里面对结果进行处理

    //本地推送通知
    -(void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
    {
        //成功注冊registerUserNotificationSettings:后,回调的方法
        NSLog(@"%@",notificationSettings);
    }
    
    -(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
    {
        //收到本地推送消息后调用的方法
        NSLog(@"%@",notification);
    }
    
    -(void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void (^)())completionHandler
    {
        //在非本App界面时收到本地消息,下拉消息会有快捷回复的button,点击button后调用的方法,依据identifier来推断点击的哪个button,notification为消息内容
        NSLog(@"%@----%@",identifier,notification);
        completionHandler();//处理完消息。最后一定要调用这个代码块
    }
    
    //远程推送通知
    -(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
    {
        //向APNS注冊成功,收到返回的deviceToken
    }
    
    -(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
    {
        //向APNS注冊失败,返回错误信息error
    }
    
    -(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
    {
        //收到远程推送通知消息
    }
    
    -(void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void (^)())completionHandler
    {
        //在没有启动本App时。收到server推送消息。下拉消息会有快捷回复的button,点击button后调用的方法,依据identifier来推断点击的哪个button
    }


    执行之后要按shift + command +H,让程序推到后台,或者按command+L让模拟器锁屏,才会看到效果。

    假设是程序退到后台了,收到消息后下拉消息,则会出现刚才加入的两个button;假设是锁屏了,则出现消息后,左划就会出现刚才加入的两个button。

    效果例如以下:

                    

    如今仅仅是能让消息中显示出button的形式,带输入框的还在研究中,假设大研究了,也谢谢分享什么啊。我们共同努力改善!

    代码:https://github.com/ios44first/PushDemo

    (转载请注明地址。谢谢 http://blog.csdn.net/yujianxiang666/article/details/35260135)


  • 相关阅读:
    0206-leetcode算法实现-反转链表reverse-linked-list-python&golang实现
    Elasticsearch集群角色类型node.master及node.data
    linux cache缓存过大导致内存资源不够用
    helm v3 调试 k8s elasticsearch集群(5)
    0203-leetcode算法实现之移除链表元素-remove-linked-list-elements-python&golang实现
    算法学习步骤
    conda 安装的坑
    matplotlib Demo
    pandas小demo
    深度学习常见问题
  • 原文地址:https://www.cnblogs.com/hrhguanli/p/4563222.html
Copyright © 2011-2022 走看看