简体   繁体   English

iOS 13 UNNotificationAction 按钮未显示

[英]iOS 13 UNNotificationAction button not showing

Actions fail to show.操作无法显示。

And, they also fail to show with these downloaded notification demo apps而且,这些下载的通知演示应用程序也无法显示
- LocalNotifications by Bart Jacobs - Bart Jacobs 的 LocalNotifications
- RemindMe by Keith Harrison (Use Your Loaf) - Keith Harrison 的 RemindMe(用你的面包)
- EatMoreVegetable by Brian Advent - Brian Advent 的 EatMoreVegetable

Interestingly, I can make action button appear by doing this:有趣的是,我可以通过这样做使操作按钮出现:
Step
1) In app, fire notification request 1)在应用程序中,触发通知请求
2) Leave app - go to Home screen 2) 离开应用程序 - go 到主屏幕
3) Notification appears without action button 3) 通知出现时没有操作按钮
4) Drag notification down causes action button to appear 4)向下拖动通知会导致出现操作按钮
Same results with simulator or device.模拟器或设备的结果相同。

My demo app can be downloaded from here我的演示应用程序可以从这里下载
https://github.com/tricarb/UNLocalDemo 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")
        }
    }
}

To get action button to show you need to swipe the notification to the left (in notification center).要让操作按钮显示您需要向左滑动通知(在通知中心)。 There you'll see three buttons: "Manage", "View", "Clear".在那里你会看到三个按钮:“管理”、“查看”、“清除”。

Select "View" and you'll get the same behavior as you have when you drag down the notification that just appeared. Select “查看”,您将获得与向下拖动刚刚出现的通知时相同的行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM