【问题标题】:How to handle NSUserNotification closed event如何处理 NSUserNotification 关闭事件
【发布时间】:2017-09-30 00:08:38
【问题描述】:

我以这种方式显示通知:

let notification = NSUserNotification()
notification.title = "Title lorem ipsum"
notification.informativeText = "Lorem ipsum"
notification.soundName = NSUserNotificationDefaultSoundName
notification.hasActionButton = true
notification.otherButtonTitle = "Other Button"
notification.actionButtonTitle = "Action Button"
NSUserNotificationCenter.default.deliver(notification)

处理通知点击事件:

func userNotificationCenter(_ center: NSUserNotificationCenter, didActivate notification: NSUserNotification) {
        switch (notification.activationType) {
        case .additionalActionClicked:
            print("Action:")
        case .actionButtonClicked:
            print("Action Button clicked")
            takeBreakClicked()
        case .contentsClicked:
            print("Contents clicked") 
        case .none:
            print("none")
        case .replied:
            print("reply clicked")
        }
    }

此通知将有 2 个按钮。问题是如何获得“其他按钮”点击事件?

【问题讨论】:

  • 问题是什么?你尝试了什么?在问题中发布您的代码。
  • 问题已更新。

标签: swift macos cocoa


【解决方案1】:

我知道这是一个老问题,答案不是特别令人满意,但也许它会节省一些时间:

我得出的结论是,当用户单击NSUserNotification 中的“关闭”按钮时,根本没有没有传递事件。 (或者您将“关闭”按钮重命名为使用 otherButtonTitle 属性的任何内容。)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    相关资源
    最近更新 更多