多个类别名称没有出现通知内容扩展?

时间:2018-02-20 12:00:48

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

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

enter image description here

将不同通知的不同类型的通知操作类别添加到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;
}]

等等。

但遗憾的是,我收到的是包含不同操作按钮的默认通知,而不是使用不同操作的自定义通知内容扩展。我无法弄清楚问题所在。如何通过不同的远程通知操作获取通知内容扩展?

1 个答案:

答案 0 :(得分:1)

只需要在通知内容扩展程序目标的Array中将 UNNotificationExtensionCategory 设为String而不是info.plist