多个类别名称未显示通知内容扩展?
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
。
【讨论】:
以上是关于多个类别名称未显示通知内容扩展?的主要内容,如果未能解决你的问题,请参考以下文章