我正在研究一个快速的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 }
通知显示完全符合我的要求.单击我定义的“查找”按钮会在第一次单击时将我的应用程序带到前台,但是我希望处理该操作的代码不会触发.
提前致谢.
将您的第二个’func notify’声明更改为’optional func userNotificationCenter’
原文链接:https://www.f2er.com/swift/319110.html