iOS8互动的新通知
iOS8一旦远程通知想必大家都很熟悉。不要做过多的描述在这里,直接推出iOS8交互式远程通知。
再看互动的通知电话,显示的形式
如今来看一下详细实现方式
一、通过调用 [[UIApplicationsharedApplication]registerForRemoteNotifications];来实现
application:didRegisterForRemoteNotificationsWithDeviceToken:和application:didFailToRegisterForRemoteNotificationsWithError:的回调
二、设置 UIUserNotificationAction和UIMutableUserNotificationCategory
UIUserNotificationAction的设置:
UIMutableUserNotificationAction *cancelAction = [[UIMutableUserNotificationAction alloc] init];
[cancelAction setIdentifier:@"CancelNotificationActionIdentifier"];
[cancelAction setTitle:@"Cancel"];
[cancelAction setActivationMode:UIUserNotificationActivationModeBackground];
[cancelAction setAuthenticationRequired:YES];
[cancelAction setDestructive:YES];
identifier
User notificaton aciton的唯一标示
title
User notificaton aciton button的显示标题
activationMode
UIUserNotificationActivationModeForeground 激活App并打开到前台展示
UIUserNotificationActivationModeBackground 在后台激活App。測试时发现假设没有启动App(App不在后台也没有打开),那么运行这样的模式下的操作,App不会打开。假设App已经在前台了,那么运行这样的模式下的操作,App依旧在前台。
authenticationRequired
假设设置为YES。运行这个操作的时候必须解锁设备。反之,无需解锁。
假设activationMode为UIUserNotificationActivationModeForeground时,authenticationRequired被作为YES处理。
測试时发现,假设用户设备有password,在锁屏时authenticationRequired设置为YES运行操作时须要用户输入password,假设设置为NO则不须要用户输入password,假设用户设备没有password,那么不管怎样设置都不须要输入password。
destructive
标示操作button是否为红色,仅仅有在锁屏和从通知中心向左滑动出现时才有这样的突出显示。在顶部消息展示时没有这样的突出效果。
UIMutableUserNotificationCategory的设置:
UIMutableUserNotificationCategory *notificationCategory = [[UIMutableUserNotificationCategory alloc] init];
[notificationCategory setIdentifier:@"NotificationCategoryIdentifier"];
[notificationCategory setActions:@[acceptAction, cancelAction]
forContext:UIUserNotificationActionContextDefault];
identifier
category的唯一标示,identifier的值与payload(从server推送到client的内容)中category值必须一致。
actions
UIUserNotificationAction 数组。假设设置为nil,那么将不会显示操作button。
context
UIUserNotificationActionContextDefault 通知操作的默认Context,在这样的情况下。你能够指定4个自己定义操作。(还未验证)
UIUserNotificationActionContextMinimal 通知操作的最小Context。在这样的情况下。你能够指定2个自己定义操作。(还未验证)
三、设置 UIUserNotificationSettings
UIUserNotificationType notificationTypes = (UIUserNotificationTypeAlert|
UIUserNotificationTypeSound|
UIUserNotificationTypeBadge);
NSSet *categoriesSet = [NSSet setWithObject:notificationCategory];
UIUserNotificationSettings *notificationSettings = [UIUserNotificationSettings settingsForTypes:notificationTypes
categories:categoriesSet];
设置通知所支持的类型和Category。这里没有难点,只是多解释。
四、注冊通知 registerUserNotificationSettings
[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
在iOS8中通过以上方式注冊通知,能够依据操作系统版本号做区分处理
五、处理回调事件
- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void (^)())completionHandler
{
if([identifier isEqualToString:@"CancelNotificationActionIdentifier"])
{
NSLog(@"You chose cancel action.");
}
else if ([identifier isEqualToString:@"AcceptNotificationActionIdentifier"])
{
NSLog(@"You chose accept action.");
} if(completionHandler)
{
completionHandler();
}
}
application
收到通知的对象
identifier
UIUserNotificationAction的唯一标示
userInfo
payload的内容
completionHandler
当运行完指定的操作后,必须在最后调用这种方法
我測试用的payload是
{
aps = {
alert = "Thank you very much";
badge = 1;
category = NotificationCategoryIdentifier;
sound = "ping.caf";
};
}
版权声明:本文博主原创文章,博客,未经同意不得转载。
iOS8互动的新通知的更多相关文章
- android6.0锁屏界面接收新通知处理流程
灭屏状态下,接收新信息,屏幕会半亮显示通知流程: 1,应用构造notification后,传给NotificationManager,而后进入NotificationManagerService处理. ...
- Android BGABadgeView:新消息/未接来电/未读消息/新通知圆球红点提示(1)
Android BGABadgeView:新消息/未接来电/未读消息/新通知圆球红点提示(1) 现在很多的APP会有新消息/未接来电/未读消息/新通知圆球红点提示,典型的以微信.QQ新消息提示为 ...
- [IOS8兼容性]IOS8上收不到通知
应用中用到了通知功能,同时有远程通知和本地通知. 测试报告应用在iphone6 plus上,收不到本地通知. 因为所有的第三方闹钟应用采用的都是本地通知方式,所以第一时间随机下载了5款不同的闹钟应用. ...
- Xcode8开发iOS10推送通知过程
iOS10发布后,简书优先开发增加了iOS10的新通知.本文分享整个feature的开发过程遇到的问题. 1.工程配置 Xcode8发生了很大的变化,直接打开原来的工程编译运行,这个时候是获取不到Pu ...
- ios10新特性-UserNotification
引言:iOS的通知分本地通知和远程通知,iOS10之前采用的是UILocationNotification类,远程通知有苹果服务器进行转发,本地通知和远程通知其回调的处理都是通过AppDelegate ...
- iOS10通知框架UserNotification理解与应用
iOS10通知框架UserNotification理解与应用 一.引言 关于通知,无论与远程Push还是本地通知,以往的iOS系统暴漏给开发者的接口都是十分有限的,开发者只能对标题和内容进行简单的定义 ...
- IOS之推送通知(本地推送和远程推送)
推送通知和NSNotification是有区别的: NSNotification:是看不到的 推送通知:是可以看到的 IOS中提供了两种推送通知 本地推送通知:(Local Notification) ...
- ios8及以前的特性
目前最新系统为ios8.以下为历代系统的回顾: iOS 1 关键词:iPhone的诞生 也许放在现在来看,当时的情景很难想象.当第一代iPhone正式发布时,在某些功能和方面其实是要远远落后于当时的竞 ...
- iOS8指纹识别TouchID
苹果在2014年6月3日的WWDC2014开幕式上推出了新版iOS8系统,界面上iOS8与iOS7相比变化不大,只是在功能方面进行了完好.iOS8通知中心更加强大,支持消息直接回复操作,并支持Quic ...
随机推荐
- hdu2647解题报告
题意:有个工厂的老板给工人发奖金,每人基础都是888,工人们有自己的想法,如:a 工人想要比 b 工人的奖金高,老板想要使花的钱最少 那么就可以 给b 888,给a 889 ,但是如果在此基础上,b也 ...
- 终于懂了:TControl.Perform是有返回值的,且看VCL框架如何利用消息的返回值(全部例子都在这里)——它的存在仅仅是为了方便复用消息的返回值
代码如下: function TControl.Perform(Msg: Cardinal; WParam, LParam: Longint): Longint; var Message: TMess ...
- CF 514C(hash)
传送门:Watto and Mechanism 题意:输入a个字符串和b个待检测字符串.问待检测字符串是否可以由某个已知字符串改变且只改变一个字母得到. 分析:字符串hash,枚举待测字符串每一位进行 ...
- LAN路由
一.实验的目的: 实现不同子网之前的信息交流 二.如果 1.虚拟子网 VMnet8:192.168.233.0/24 VMnet1:172.16.1.0/24 2.虚拟机vm1 ip:1 ...
- Android内存管理
首先Android理机制相当复杂.想要讲清楚比較困难.其次对于绝大多数用户来说.仅仅关心内存够不够用,至于内存怎样管理的这样的技术细节,不是用户须要去考虑的,写这样一个专题有没有意义?毕竟我们是用手机 ...
- linux find命令强大之处
find命令 find pathname -options [-print -exec -ok ...] -print: find命令将匹配的文件输出到标准输出. -exec: find命令对 ...
- SSH WebShell: SSH在线WEB管理器安装教程 - VPS管理百科
SSH WebShell: SSH在线WEB管理器安装教程 - VPS管理百科 SSH WebShell: SSH在线WEB管理器安装教程 本站原创 [基于 署名-非商业使用-相同方式分享 2.5 协 ...
- Struts2 后台action接收 jsp页面中checkbox中的值
如前端页面jsp中的标签为: <form action="myurl"> <input type="checkbox" name=" ...
- 【Qt for Android】OpenGL ES 绘制彩色立方体
Qt 内置对OpenGL ES的支持.选用Qt进行OpenGL ES的开发是很方便的,很多辅助类都已经具备.从Qt 5.0開始添加了一个QWindow类,该类既能够使用OpenGL绘制3D图形,也能够 ...
- Android wear 初体验
近期一直在研究android wear SDK,整体感受来说就是和现有的android 其它的开发SDK还是有非常多新的东西.比如手机终端与手表端的通信机制,手表端的UI规范.可是从开发本身来讲,还是 ...