作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在开发一个 swift 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 notify”声明更改为“optional func userNotificationCenter”
关于macos - Swift NSUserNotificationCenter didActivateNotification 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27428590/
我正在努力让 osx native 通知正常工作。我可以创建通知,但无法使 didActivateNotification 正常工作。我希望 didActivateNotification 允许我聚焦
我正在开发一个 swift os x 应用程序,但我无法理解 userNoticiation/didActivateNotification 结构。我已经查看了文档并进行了搜索,但仍然卡住了。非常感谢
从 MacOS 10.13 开始,每次我点击 NSUserNotification 上的关闭按钮时,它都会调用: - (void) userNotificationCenter:(NSUserNoti
我是一名优秀的程序员,十分优秀!