Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift NSUserNotificationCenter didActivateNotification not working

I'm working on a swift os x application and I'm having trouble understanding the userNoticiation / didActivateNotification structure. I've reviewed the documentation and searched SO but am still stuck. Any guidance on the following code would be much appreciated:

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
}

The notification displays exactly as I'd like it to. Clicking the "Lookup" button that I've defined will bring my app to the foreground the first time it is clicked, but the code I'd expect to handle that action does not fire.

Thanks in advance.

like image 385
Brian Randolph Avatar asked Dec 11 '14 17:12

Brian Randolph


1 Answers

Change your second 'func notify' declaration to 'optional func userNotificationCenter'

like image 195
Donald P Avatar answered Sep 28 '22 05:09

Donald P