用户点击了一个 Action(如赞、踩、关注、甚至评论等)

WWDC 2017 Session笔记 - Session 708 推送消息新功能和最佳实践(Best Practices and What’s New in User Notifications)

 

WWDC 2017 Session笔记 - Session 708 推送消息新功能和最佳实践Best Practices and Whats New in User Notifications Content Notification Management Notification Actions Hidden Notificaition Content Service Extendsion Notification Content 小结

 

本地和推送通知使您的应用程序能够通过显示消息并接受用户的操作,播放独特的声音或更新应用程序图标上的徽章,使用户及时了解相关内容。服务扩展功能使您的应用程序能够在显示之前解密并扩充推送通知内容。了解什么是新功能,并获得有关在您的应用程序中实施用户通知的专家建议。

Best Practices and What’s New in User Notificati

Content

以前只能展示一条文字,现在可以有 title 、subtitle 以及 body 了 Alt text 代码示例:

//Local Notification
UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
content.title = @"Introduction to Notifications";
content.subtitle = @"Session 707";
content.body = @"Woah! These new notifications look amazing! Don’t you agree?";
content.badge = @1;

//Remote Notification
{
"aps" : {
    "alert" : { 
         "title" : "Introduction to Notifications", 
         "subtitle" : "Session 707",         
         "body" : "Woah! These new notifications look amazing! Don’t you agree?"
                },
    "badge" : 1
        },
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18

Notification Management

彻底掌控整个推送周期: * Local Notification 通过更新 request * Remote Notification 通过新的字段 apns-collapse-id

通过之前的 addNotificationRequest: 方法,在 id 不变的情况下重新添加,就可以刷新原有的推送。

NSString *requestIdentifier = @"sampleRequest"; 
UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:requestIdentifier content:newContent trigger:newTrigger1]; 
[center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) { }];
1 2 3

Notification Actions

在 iOS 10 中,可以允许推送添加交互操作 action,这些 action 可以使得 App 在前台或后台执行一些逻辑代码。并且在锁屏界面通过 3d-touch 触发。如:推出键盘进行快捷回复,该功能以往只在 iMessage 中可行。Notification Actions 在 iOS 8 引入,快捷回复在 iOS 9 引入,在 iOS 10 中,这些 API 被统一。

Hidden Notificaition Content

例子:系统信息app

用户可以通过Setting统一配置是否显示详情, 先开放api

可以配置identifier, 显示信息的类别

Service Extendsion

有时间限制地执行一段代码

先发送视频url, 本地下载后作为attachment后再展示, 有下载不成功的情况, 有一系列异常的回调

可以在手机「接收到推送之后、展示推送之前」对推送进行处理,更改、替换原有的内容。

使用它,原有发送推送的 payload 可以完全不变,而在客户端对接收到的内容(只有一条字符串)进行加工,从而适配 iOS 10 的展示效果(标题+副标题+内容)。

Different from silent notificati

Notification Content

iOS 10 新增的另一项 Extension,用于完全自定义推送展示的 UI 界面,响应 Actions 的同时刷新该 UI。简单的说就是你可以把需要推送的内容(比如一条完整的新闻快讯,包括多条文字+图片的组合)全部放到一条推送里,用户点击了一个 Action(如赞、踩、关注、甚至评论等),在推送里立刻刷新 UI(如展示加星动画、评论内容等)。

特点

需要添加 Notification content extension 完全自定义 UI 推送 UI 不能响应触摸、点击、滑动等任何手势 可以响应 notification actions ####NotificationViewController.h/m 继承自 UIViewController,并实现了 UNNotificationContentExtension 协议。 可以在 viewDidLoad 里定制你想要的 UI 在 didReceiveNotification 方法里接收推送内容,然后各种处理逻辑、传值、展示 UI 等等。当点击了 actions,也会走到这里,并且包含一个 action 的字段,判断点击了哪个 action 进而相应的更新你的 UI。 ###Content Extension 有一个独立的ViewController, 可以自己定制Notification使用3D Touch展开后的UI和内容 ###User Input Customization Alt text Media buttons :play pause

Action :可定制, 例如点赞, 评论

Custom Input View:整个底部的空间可以定制一个View

小结

感觉 Notification Content 的功能极其强大,有了它之后连 App 都不需要再启动了的样子(只要能合理的设计展示内容和操作),省去了用户每次为了一项简单操作都要进行「启动 App - 操作 - 切换到多任务界面 - 退出 App」这样的繁琐过程。原本用户看到推送可能不太有意愿去查看详细内容,现在他只需要很简单的操作就能快速的查看,大幅提升用户点击通知的意愿 究其如此便捷的原因,Notification Service Extension 和 Notification Content 都是独立于项目的 target,收到推送后,系统会单独运行这两个 target,完全不会在此时去启动 App 并执行 App 中大量的代码,童鞋们在调试的时候也可以注意这一点。

文章来源:

Author:海博1600
link:https://my.oschina.net/u/3264768/blog/1592704