通知内容扩展没有出现多个类别名称?
Notification Content Extension is not appearing for multiple category name?
我已将自定义远程通知内容扩展添加到我的项目中,并将多个扩展类别添加到 通知内容扩展目标 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 以下方式:
对于Open tickets获取类别名称为"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;
}]
等等。
但不幸的是,我收到的是带有不同操作按钮的默认通知,而不是带有不同操作的自定义通知内容扩展。我无法弄清楚问题所在。如何获得具有不同远程通知操作的通知内容扩展?
只需要将UNNotificationExtensionCategory设为Array
而不是通知内容的info.plist
中的String
扩展目标。
我已将自定义远程通知内容扩展添加到我的项目中,并将多个扩展类别添加到 通知内容扩展目标 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 以下方式:
对于Open tickets获取类别名称为"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;
}]
等等。
但不幸的是,我收到的是带有不同操作按钮的默认通知,而不是带有不同操作的自定义通知内容扩展。我无法弄清楚问题所在。如何获得具有不同远程通知操作的通知内容扩展?
只需要将UNNotificationExtensionCategory设为Array
而不是通知内容的info.plist
中的String
扩展目标。