简介
iOS中可以通过两个Extension来推送消息
UNNotificationServiceExtension(通知服务扩展)
An object that modifies the content of a remote notification before it's delivered to the user.
在收到推送后,展示推送前可以做一些事情,例如增加附件、网络请求等操作,用户不需要打开App就可以快速浏览内容
UNNotificationContentExtension(通知内容扩展)
An object that presents a custom interface for a delivered local or remote notification.
可以自定义推送界面,但这个界面不能接受任何点击事件,与用户没有交互,交互需要使用Notification的actions来处理交互事件。
与一般推送不一样,Push Story是一条2页以上6页一下,带图片通过Braze平台发布的推送,这里是Braze配置Push Story的官方文档
第一步
在项目中添加一个Notification Content Extension Target,项目中会有一个新的文件夹包括
NotificationViewController.swift
MainInterface.storyboard
Info.plist
第二步
在主程序中开启Background fetch和Remote Notification两个选项

并添加用于和主程序共享数据的APP Group,主程序和Extension都需要勾选同一个APP Group
AppGroup: allows data sharing between two different apps or even app and widgets by creating one common shared path (like document directory). Data saved over there can be accessed by any app which is associated with that particular AppGroup. It is an offline data sharing between apps.
简单说就是一个连接主程序和Extension的桥梁

第三步
在Extension的Linked Frameworks and Libraries中添加AppboyPushStory.framework

第四步
在MainInterface.storyboard中按照需求完成Push Notification的布局,UNNotificationServiceExtension与UNNotificationContentExtension最大的不同就是后者可以自定义界面
在NotificationViewController.swift写必要的代码处理数据源
class NotificationViewController: UIViewController, UNNotificationContentExtension {
@IBOutlet weak var storiesView: ABKStoriesView!
var dataSource: ABKStoriesViewDataSource!
func didReceive(_ notification: UNNotification) {
dataSource = ABKStoriesViewDataSource(notification: notification, storiesView: storiesView, appGroup: "your app group")
}
func didReceive(_ response: UNNotificationResponse, completionHandler completion: @escaping (UNNotificationContentExtensionResponseOption) -> Void) {
let option: UNNotificationContentExtensionResponseOption = dataSource.didReceive(response)
completion(option)
}
override func viewWillDisappear(_ animated: Bool) {
dataSource.viewWillDisappear()
super.viewWillDisappear(animated)
}
}
第五步
在主程序中更新集成Braze的配置
let appboyOptions = [ABKPushStoryAppGroupKey: "your app group"]
Appboy.start(withApiKey: Constants.brazeToken, in: application, withLaunchOptions: launchOptions, withAppboyOptions: appboyOptions)
第六步
在plist中完成设置


plist中
UNNotificationExtensionDefaultContentHidden :是否显示默认的部分,就是Notification的题目与内容体UNNotificationExtensionInitialContentSizeRatio :是Notification的横纵比,可以根据需求设置UNNotificationExtensionCategory:是控制Notification Action的,需要在Appdelegate中写相应的代码,否则不会出现Notification Action
这里的UNNotificationExtensionCategory = ab_cat_push_story_v2是因为Braze已经封装好了对应的5种情况,见下图

到这里就是官方文档对于Push Story的配置指导,按照这个流程走下来发现效果和网站预览的并不一样

第七步
设置Categorise将Braze封装好的取出来加进NotificationCategories中
let appboyCategorise = ABKPushUtils.getAppboyUNNotificationCategorySet()
UNUserNotificationCenter.current().setNotificationCategories(appboyCategorise)
按照这八部走下来,通过Braze平台推松Push Story就完成啦,下面是最终结果

ps:此文章针对已经配置好Braze推送的情况,就是官网文档对应的第一步
未经授权,禁止转载!
尊重原创,转载请注明出处,谢谢!