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 ...
随机推荐
- 改动已有gpg密钥的用户标识及凝视
/********************************************************************* * Author : Samson * Date ...
- OpenCV五学习: 如何使用命令来启动或关闭OpenCV的CPU指令系统CV_SSE2,CV_SSSE4和其他优化
在这个博客.我想分享一下OpenCV源代码CPU指令系统CV_SSE2和其他相关知识 一个. CV_SSE系列指令集的预编译符号定义在opencv2/core/internal.hpp这个头文件 ...
- WebSocket是一种协议
WebSocket,并非HTML 5独有,WebSocket是一种协议.只是在handshake的时候,发送的链接信息头和HTTP相似.HTML 5只是实现了WebSocket的客户端.其实,难点在于 ...
- 第二章排错的工具:调试器Windbg(下)
感谢博主 http://book.51cto.com/art/200711/59874.htm 2.2 读懂机器的语言:汇编,CPU执行指令的最小单元2.2.1 需要用汇编来排错的常见情况 汇编是 ...
- Keywords Search (ac 自己主动机)
Keywords Search Problem Description In the modern time, Search engine came into the life of everybod ...
- linux内存基础知识和相关调优方案
内存是计算机中重要的部件之中的一个.它是与CPU进行沟通的桥梁. 计算机中全部程序的执行都是在内存中进行的.因此内存的性能对计算机的影响很大.内存作用是用于临时存放CPU中的运算数据,以及与硬盘等外部 ...
- [Network]Wireless and Mobile
Wireless 1 Introduction 1.1 Elements 1. Wireless Hosts Wireless does not mean mobility. 2. Base Stat ...
- TCP/IP详细解释--TCP/IP可靠的原则 推拉窗 拥塞窗口
TCP和UDP在同一水平---传输层.但TCP和UDP最不一样的地方.TCP它提供了一个可靠的数据传输服务,TCP是面向连接的,那.使用TCP两台主机通过第一通信"拨打电话"这个过 ...
- php设计模式——UML类图
前言 用php开发两年多了,准备也写一下平时常用的设计模式,都是基于自己的实践经验,当然,用设计模式之前首先要看懂设计模式,因此这里首先讲解一下UML类图.通过UML类图,能更好的和大家交流,也能很容 ...
- 一张图总结Google C++编程规范(Google C++ Style Guide)
Google C++ Style Guide是一份不错的C++编码指南,我制作了一张比較全面的说明图,能够在短时间内高速掌握规范的重点内容.只是规范毕竟是人定的,记得活学活用.看图前别忘了阅读以下三条 ...