多个类别名称未显示通知内容扩展?

Posted

技术标签:

【中文标题】多个类别名称未显示通知内容扩展?【英文标题】: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;
]

等等。

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

【问题讨论】:

【参考方案1】:

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

【讨论】:

以上是关于多个类别名称未显示通知内容扩展?的主要内容,如果未能解决你的问题,请参考以下文章

收到短信时,联系人姓名未显示在通知中

在 MacOs/OSX 上未显示 Chrome 扩展通知按钮

自定义操作按钮未显示远程通知

通知内容标题和内容文本未显示

调试时未调用推送通知扩展

远程通知类别未发送到客户端设备?