首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何处理NSUserNotification关闭事件

如何处理NSUserNotification关闭事件
EN

Stack Overflow用户
提问于 2017-09-30 08:08:39
回答 1查看 392关注 0票数 2

我以这种方式显示一个通知:

代码语言:javascript
复制
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)

处理通知点击事件:

代码语言:javascript
复制
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")
        }
    }

此通知将有两个按钮。问题是如何获取"Other Button“点击事件?

EN

回答 1

Stack Overflow用户

发布于 2020-09-22 23:13:28

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

我得出的结论是,当用户单击NSUserNotification中的"Close“按钮时,根本就没有事件传递的。(或者使用otherButtonTitle属性将"Close“按钮重命名为其他任何名称。)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46498309

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档