Swift NSUserNotificationCenter doActivateNotification无效

时间:2014-12-11 17:12:47

标签: macos swift nsusernotification nsusernotificationcenter

我正在使用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
}

通知显示与我喜欢的完全相同。单击"查找"我已定义的按钮会在第一次点击时将我的应用程序带到前台,但我希望处理该操作的代码不会触发。

提前致谢。

1 个答案:

答案 0 :(得分:5)

将您的第二个'func notify'声明更改为'optional func userNotificationCenter'