iOS 13 UNNotificationAction按钮未显示

时间:2020-06-18 22:14:26

标签: ios xcode notifications action

操作无法显示。

而且,它们也无法与这些下载的通知演示应用一起显示
-Bart Jacobs的LocalNotifications
-Keith Harrison的RemindMe(使用面包)
-Brian Advent的EatMoreVegetable

有趣的是,我可以通过以下操作使操作按钮出现:
步骤
1)在应用中,发出火灾通知请求
2)离开应用-转到主屏幕
3)出现没有动作按钮的通知
4)向下拖动通知会导致出现操作按钮
与模拟器或设备的结果相同。

可以从此处下载我的演示应用程序
https://github.com/tricarb/UNLocalDemo

func registerCategories() {

    let center = UNUserNotificationCenter.current()

    let actionID = Notify.actionID.rawValue
    let categoryID = Notify.categoryId.rawValue

    let action = UNNotificationAction(identifier: actionID, title: "Action Title", options: [.foreground])
    let category = UNNotificationCategory(identifier: categoryID, actions: [action], intentIdentifiers: [])
    center.setNotificationCategories([category])
}

func fireNotification() {

    let content = UNMutableNotificationContent()
    content.title = "Content Title"
    content.body = "This is the content body"
    content.categoryIdentifier = Notify.categoryId.rawValue

    let timeInterval = TimeInterval(7)
    let trigger = UNTimeIntervalNotificationTrigger(timeInterval: timeInterval, repeats: false)
    let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger)
    let center = UNUserNotificationCenter.current()

    center.add(request) { (error) in
        if let error = error {
            print(error.localizedDescription)
        } else {
            print("Notification will fire in", timeInterval, "seconds")
        }
    }
}

1 个答案:

答案 0 :(得分:0)

要显示操作按钮,您需要向左滑动通知(在通知中心)。在那里,您将看到三个按钮:“管理”,“查看”,“清除”。

选择“查看”,您将获得与拖下刚刚出现的通知时相同的行为。