ios - 在 Swift 4 中将 UNNotificationAction 添加到 Firebase FCM 推送通知
问题描述
我正在尝试在 FCM 推送通知时添加一些自定义操作。我在注册通知后尝试添加这些。
UNUserNotificationCenter.current().delegate = self
let acceptAction = UNNotificationAction(identifier: "ACCEPT_ACTION",
title: "Accept",
options: UNNotificationActionOptions(rawValue: 0))
let declineAction = UNNotificationAction(identifier: "DECLINE_ACTION",
title: "Decline",
options: UNNotificationActionOptions(rawValue: 0))
let center = UNUserNotificationCenter.current()
if #available(iOS 11.0, *) {
let meetingInviteCategory = UNNotificationCategory(identifier: "MEETING_INVITATION",
actions: [acceptAction, declineAction],
intentIdentifiers: [],
hiddenPreviewsBodyPlaceholder: "",
options: .customDismissAction)
center.setNotificationCategories([meetingInviteCategory])
}
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
center.requestAuthorization(
options: authOptions,
completionHandler: {_, _ in })
但不幸的是,该动作仍未出现。有没有办法做到这一点?这就是我想要达到的目标。
我的 firebase FCM 设置和所有通知工作正常。我只是无法为这些通知添加操作。
解决方案
我知道了。我只需要在 fcm/send 的正文中添加 click_action 字段。并将 click_action 键设置为类别标识符。
推荐阅读
- angular - 我可以在构造函数和 ngOnInit 中调度请求操作吗?
- javascript - 遍历查询集中传递给模板的特定数量的元素
- python - 当多个线程访问一个类变量时,该变量是所有线程共有的吗?
- c# - 在 EventSourcing 中,关于订阅的公认智慧是什么?
- javascript - 使用 Redux 在 Axios 调用后更新 React 组件状态
- eiffel - 埃菲尔:多个通用约束的语法错误
- mongodb - 如何验证在连接级别设置的 mongoDB 选项
- angular - ngx-quill / quill.js 自定义印迹操作
- python - 在对帧进行排序时使用 try 语句
- angular - 有什么方法可以调试为什么角度路线没有被识别?