【问题标题】:Notification Content Extension is not appearing for multiple category name?多个类别名称未显示通知内容扩展?
【发布时间】:2018-02-20 12:00:47
【问题描述】:

我已将自定义远程通知内容扩展添加到我的项目中,并将多个扩展类别添加到 通知内容扩展目标 info.plist 文件中,如下所示:

AppDelegate中为不同的通知添加了不同类型的通知操作类别:

 func addRichRotificationActions() {
        let confirmAction = UNNotificationAction(identifier: "ConfirmAction", title: "Confirm", options: [.foreground])
        let cancelAction = UNNotificationAction(identifier: "CancelAction", title: "Cancel", options: [.destructive])
        let closeAction = UNNotificationAction(identifier: "CloseAction", title: "Close", options: [.foreground])

        let openTicketCategory = UNNotificationCategory(identifier: "OpenTicket", actions: [confirmAction, cancelAction], intentIdentifiers: [], options: [])
        let confirmTicketCategory = UNNotificationCategory(identifier: "ConfirmTicket", actions: [closeAction, cancelAction], intentIdentifiers: [], options: [])
        let closeTicketCategory = UNNotificationCategory(identifier: "CloseTicket", actions: [], intentIdentifiers: [], options: [])
        let cancelTicketCategory = UNNotificationCategory(identifier: "CancelTicket", actions: [], intentIdentifiers: [], options: [])

        UNUserNotificationCenter.current().setNotificationCategories([openTicketCategory, confirmTicketCategory, closeTicketCategory, cancelTicketCategory])
    }

现在我通过以下方式发送 apns json:

对于 OpenTicket 获取类别名称为 "OpenTicket"

[AnyHashable("default"): You have a new ticket, AnyHashable("aps"): {
    alert = "#8556 - New Booking for Mr. Tomas";
    badge = 1;
    category = OpenTicket;
    "mutable-content" = 1;
    sound = default;
}]

对于ConfirmTicket,将类别名称设为“ConfirmTicket”

[AnyHashable("default"): You have a confirmed ticket, AnyHashable("aps"): {
    alert = "#8556 - Ticket Confirmed for Mr. Tomas";
    badge = 1;
    category = ConfirmTicket;
    "mutable-content" = 1;
    sound = default;
}]

等等。

但不幸的是,我收到的是带有不同操作按钮的默认通知,而不是带有不同操作的自定义通知内容扩展。我无法弄清楚问题所在。如何获得具有不同远程通知操作的通知内容扩展?

【问题讨论】:

    标签: swift3 apple-push-notifications ios10 unusernotificationcenter rich-notifications


    【解决方案1】:

    只需要在Notification Content Extension目标的info.plist中将UNNotificationExtensionCategory设为Array而不是String

    【讨论】:

      猜你喜欢
      • 2017-02-24
      • 2019-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-11
      • 1970-01-01
      • 2014-09-17
      相关资源
      最近更新 更多