我以这种方式显示通知:
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个按钮。问题是如何获得"其他按钮"点击事件?
答案 0 :(得分:0)
我知道这是一个古老的问题,答案不是特别令人满意,但是也许可以节省一些时间:
我得出的结论是,当用户单击NSUserNotification
中的“关闭”按钮时,根本没有未交付事件。 (或者将“关闭”按钮重命名为使用otherButtonTitle
属性的任何内容。)