我正在开发一个 swift os x 应用程序,但我无法理解 userNoticiation / didActivateNotification 结构。我已经查看了文档并搜索了 SO,但仍然卡住了。任何有关以下代码的指导将不胜感激:
func notify(message: String, callBack: String) {
println(message)
println(callBack)
var notification:NSUserNotification = NSUserNotification()
notification.title = "New Phone Call"
notification.informativeText = message
notification.actionButtonTitle = "Lookup"
notification.hasActionButton = true
var center:NSUserNotificationCenter = NSUserNotificationCenter.defaultUserNotificationCenter()
center.delegate = self
center.scheduleNotification(notification)
}
func notify (center: NSUserNotificationCenter, didActivateNotification notification: NSUserNotification){
center.delegate = self
println("clicked") //this does not print
}
通知完全按照我的意愿显示。单击我定义的“查找”按钮将在第一次单击时将我的应用程序带到前台,但我希望处理该操作的代码不会触发。
提前致谢。