【问题标题】:Adding UNNotificationAction to firebase FCM push notification in Swift 4在 Swift 4 中将 UNNotificationAction 添加到 Firebase FCM 推送通知
【发布时间】:2019-09-16 05:13:05
【问题描述】:

我正在尝试在 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 设置和所有通知工作正常。我只是无法为这些通知添加操作。

【问题讨论】:

    标签: ios swift firebase-cloud-messaging


    【解决方案1】:

    我明白了。我只需要在 fcm/send 的正文中添加 click_action 字段。并将 click_action 键设置为类别标识符。

    【讨论】:

    • 是的,我只能在 2 天后接受我的回答,这就是原因。谢谢
    猜你喜欢
    • 2017-02-05
    • 1970-01-01
    • 2022-08-22
    • 1970-01-01
    • 1970-01-01
    • 2021-02-21
    • 2017-10-10
    • 1970-01-01
    • 2018-03-22
    相关资源
    最近更新 更多