当前位置: 首页 > news >正文

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)


相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • Tiny模板编辑器
  • windows整体性能检测
  • 我的书签
  • 16 行为型模式-----备忘录模式
  • Nodejs部署再思考
  • root权限引发的/sbin/init不存在故障的血案
  • python代码`if not x:` 和`if x is not None:`和`if not x is None:`
  • USB那点事3 -使用端口2作为custom HID的传输(转)
  • CentOS开启FTP及配置用户
  • IOS 打开相机和相册的方法
  • DirectSound应用
  • C语言及程序设计进阶例程-25 排序问题及其求解
  • ThinkPhp学习09
  • TCP/IP详解学习笔记(6)-UDP协议
  • Kotlin:Android世界的Swift
  • ES学习笔记(10)--ES6中的函数和数组补漏
  • golang 发送GET和POST示例
  • Java 多线程编程之:notify 和 wait 用法
  • JSDuck 与 AngularJS 融合技巧
  • React Transition Group -- Transition 组件
  • SQLServer插入数据
  • 彻底搞懂浏览器Event-loop
  • 官方解决所有 npm 全局安装权限问题
  • 极限编程 (Extreme Programming) - 发布计划 (Release Planning)
  • 简单基于spring的redis配置(单机和集群模式)
  • 开发了一款写作软件(OSX,Windows),附带Electron开发指南
  • 那些年我们用过的显示性能指标
  • 浅析微信支付:申请退款、退款回调接口、查询退款
  • 让你成为前端,后端或全栈开发程序员的进阶指南,一门学到老的技术
  • 世界编程语言排行榜2008年06月(ActionScript 挺进20强)
  • 我的业余项目总结
  • ​iOS安全加固方法及实现
  • ​十个常见的 Python 脚本 (详细介绍 + 代码举例)
  • (13)Hive调优——动态分区导致的小文件问题
  • (done) ROC曲线 和 AUC值 分别是什么?
  • (Python) SOAP Web Service (HTTP POST)
  • (二)丶RabbitMQ的六大核心
  • (六) ES6 新特性 —— 迭代器(iterator)
  • (免费领源码)Python#MySQL图书馆管理系统071718-计算机毕业设计项目选题推荐
  • (牛客腾讯思维编程题)编码编码分组打印下标(java 版本+ C版本)
  • (贪心) LeetCode 45. 跳跃游戏 II
  • (学习日记)2024.04.04:UCOSIII第三十二节:计数信号量实验
  • (转)Android中使用ormlite实现持久化(一)--HelloOrmLite
  • .【机器学习】隐马尔可夫模型(Hidden Markov Model,HMM)
  • .NET Core 2.1路线图
  • .net core 连接数据库,通过数据库生成Modell
  • .net framework4与其client profile版本的区别
  • .net遍历html中全部的中文,ASP.NET中遍历页面的所有button控件
  • .NET是什么
  • .net中生成excel后调整宽度
  • .Net转前端开发-启航篇,如何定制博客园主题
  • [20190113]四校联考
  • [ACP云计算]组件介绍
  • [C]整形提升(转载)
  • [C++]运行时,如何确保一个对象是只读的