【发布时间】: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 个按钮。问题是如何获得“其他按钮”点击事件?
【问题讨论】:
-
问题是什么?你尝试了什么?在问题中发布您的代码。
-
问题已更新。