我以这种方式显示一个通知:
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")
}
}此通知将有两个按钮。问题是如何获取"Other Button“点击事件?
发布于 2020-09-22 23:13:28
我知道这是一个古老的问题,答案也不是特别令人满意,但也许它会节省一些时间:
我得出的结论是,当用户单击NSUserNotification中的"Close“按钮时,根本就没有事件传递的。(或者使用otherButtonTitle属性将"Close“按钮重命名为其他任何名称。)
https://stackoverflow.com/questions/46498309
复制相似问题