我已将自定义远程通知内容扩展添加到我的项目中,并将多个扩展类别添加到通知内容扩展目标 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”的公开票:
[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”的确认票:
[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;
}]
等等。
但不幸的是,我收到的是带有不同操作按钮的默认通知,而不是带有不同操作的自定义通知内容扩展。我无法弄清楚问题所在。如何获得具有不同远程通知操作的通知内容扩展?