我正在开发一个快速的OS X应用程序,但在理解userNoticiation/didActivateNotification结构时遇到了麻烦。我已经查看了文档并进行了搜索,但仍然陷于困境。对于以下代码的任何指导将不胜感激:
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
}
通知将完全按照我的意愿显示。单击我定义的“查找”按钮将在第一次单击时将我的应用程序置于前台,但是我希望处理该操作的代码不会触发。
提前致谢。
最佳答案
将您的第二个“功能通知”声明更改为“可选的func userNotificationCenter”