iOS8推送消息的快速回复处理
http://blog.csdn.net/yujianxiang666/article/details/35260135
iOS8拥有了全新的通知中心,有全新的通知机制。当屏幕顶部收到推送时只需要往下拉,就能看到快速操作界面,并不需要进入该应用才能操作。在锁屏界面,对于推送项目也可以快速处理。基本上就是让用户尽量在不离开当前页面的前提下处理推送信息,再次提高处理效率。
能够进行直接互动的短信、邮件、日历、提醒,第三方应用,可以让你不用进入程序就能进行快捷操作,并专注于手中正在做的事情。
- 在通知横幅快速回复信息,不用进入短信程序;
- 可直接拒绝或接受邮件邀请;
- 可对提醒进行标记为完成或推迟;
- 当第三方应用更新接口后便可直接对应用进行快速操作。
最近研究了下iOS8的官方文档,对这项功能进行了钻研,基本上效果已经出来。因为远程消息推送比较繁琐,需要后台支持,所以我用本地推送来代替的,基本上它们要调用的代理方法类似。长话短说,下面我就说下基本的流程:
1.创建消息上面要添加的动作(按钮的形式显示出来)
- UIMutableUserNotificationAction *action = [[UIMutableUserNotificationAction alloc] init];
- action.identifier = @"action";//按钮的标示
- action.title=@"Accept";//按钮的标题
- action.activationMode = UIUserNotificationActivationModeForeground;//当点击的时候启动程序
- // action.authenticationRequired = YES;
- // action.destructive = YES;
- UIMutableUserNotificationAction *action2 = [[UIMutableUserNotificationAction alloc] init]; //第二按钮
- action2.identifier = @"action2";
- action2.title=@"Reject";
- action2.activationMode = UIUserNotificationActivationModeBackground;//当点击的时候不启动程序,在后台处理
- action.authenticationRequired = YES;//需要解锁才能处理,如果action.activationMode = UIUserNotificationActivationModeForeground;则这个属性被忽略;
- action.destructive = YES;
2.创建动作(按钮)的类别集合
- 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 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设置的按钮,和响应按钮事件。
// 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界面时收到本地消息,下拉消息会有快捷回复的按钮,点击按钮后调用的方法,根据identifier来判断点击的哪个按钮,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时,收到服务器推送消息,下拉消息会有快捷回复的按钮,点击按钮后调用的方法,根据identifier来判断点击的哪个按钮
- }
运行之后要按shift + command +H,让程序推到后台,或者按command+L让模拟器锁屏,才会看到效果!
如果是程序退到后台了,收到消息后下拉消息,则会出现刚才添加的两个按钮;如果是锁屏了,则出现消息后,左划就会出现刚才添加的两个按钮。
效果如下:
现在只是能让消息中显示出按钮的形式,带输入框的还在研究中,如果大家研究出来了,也谢谢能分享一下啊,大家一起提高!
代码:https://github.com/ios44first/PushDemo
(如要转载请注明地址,谢谢 http://blog.csdn.net/yujianxiang666/article/details/35260135)
iOS8推送消息的快速回复处理的更多相关文章
- iOS8推送消息的回复处理速度
iOS8我们有一个新的通知中心,我们有一个新的通报机制.当在屏幕的顶部仅需要接收一个推拉向下,你可以看到高速接口,天赋并不需要输入应用程序的操作.锁定屏幕,用于高速处理可以推动项目. 推送信息,再次提 ...
- IOS中程序如何进行推送消息(本地推送,远程推送)
[1]-------------什么是推送消息? 我就以一张图解释------------ [2]-----------IOS程序中如何进行本地推送?----------- 2.1,先征求用户同意 1 ...
- IOS 本地通知推送消息
在现在的移动设备中,好多应用性的APP都用到了推送服务,但是有好多推送的内容,比如有的只是单纯的进行推送一个闹钟类型的,起了提醒作 用,有的则是推送的实质性的内容,这就分为推送的内容来区别用什么推送, ...
- 点击推送消息跳转处理(iOS)
当用户点击收到的推送消息时候,我希望打开APP,并且跳转到对应的界面,这就需要在AppDelegate里面对代理方法进行处理. 当用户点击推送消息打开APP的时候会调用 - (BOOL)applica ...
- iOS 远程推送消息解析及逻辑处理
关于远程推送的相关配置网上已经有足够多的教程,这里就不复述了.这里讲述当客户端收到推送消息后,应怎样对其进行相应的逻辑处理. 工程的AppDelegate.m文件里提供了如下方法: //当应用程序启动 ...
- iOS监听模式系列之推送消息通知
推送通知 和本地通知不同,推送通知是由应用服务提供商发起的,通过苹果的APNs(Apple Push Notification Server)发送到应用客户端.下面是苹果官方关于推送通知的过程示意图: ...
- 微信硬件平台(八) 4 ESP8266通过微信公众号给用户推送消息
https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=自己申请微信公众号的TOKEN 输出结果: 由于aRDUINO串 ...
- 极光推送消息——Alias别称方式(Andirod)
1.pom文件引入相关jar包 <!--极光推送消息start--> <dependency> <groupId>net.sf.json-lib</group ...
- 使用PushSharp给iOS应用推送消息
PushSharp是一个C#编写的服务端类库,用于推送消息到各种客户端,支持iOS(iPhone/iPad).Android.Windows Phone.Windows 8.Amazo.Blackbe ...
随机推荐
- ShellExecute快捷键大全
文件夹,文件,网址可以创建快捷方式,控制面板 中的设置也可以创建快捷方式,下面是快捷方式的命令,使用方法:在桌面或文件夹的空白处点右键,选择新建,快捷方式,在"请键入项目的位置"输 ...
- 转载 Deep learning:七(基础知识_2)
前面的文章已经介绍过了2种经典的机器学习算法:线性回归和logistic回归,并且在后面的练习中也能够感觉到这2种方法在一些问题的求解中能够取得很好的效果.现在开始来看看另一种机器学习算法--神经网络 ...
- myEclipse JSP 调用 IDL8.2 配置
新安装了Envi5.0 IDL8.2,路径改动了,一些配置也要随之改动.现在总结一下,JSP调用IDL的配置. jar包配置,环境变量配置,dll配置,tomcat路径配置,tomcat运行选项配置, ...
- WindowsAPI 之 CreatePipe、CreateProcess
MSDN介绍 CreatePipe A pipe is a section of shared memory that processes use for communication. The pro ...
- PAT1003
As an emergency rescue team leader of a city, you are given a special map of your country. 作为一个城市的紧急 ...
- hdu_1007_Quoit Design(最近点对)
题目连接:hdu_1007_Quoit Design 题意: 给你平面上的一些点,让你找出这些点的最近点对的距离 题解: 采用分治,达到O(nlognlogn)的时间复杂度就能艹过去了 #includ ...
- jq的事件对象的属性
1.event.type() 该方法的作用是可以获取到时间的类型 $('a').click(function(){ alert(event.type);//获取事件类型 return false;/ ...
- Java与C#的比较学习
http://www.cnblogs.com/javathread/archive/2012/08/11/2634893.html 我在大学学的是C语言,自学和选修的是C++,刚毕业也搞过几天Jsp, ...
- C#入门经典第11章集合-1
- 关于Tcpreplay
tcpprep -p -o /root/Desktop/ZS/Tcpreplay/cache_test.cache -i /root/Desktop/ZS/Tcpreplay/9.17.pcap tc ...