gpt4 book ai didi

macos - Swift NSUserNotificationCenter didActivateNotification 不工作

转载 作者:搜寻专家 更新时间:2023-10-30 21:57:52 25 4
gpt4 key购买 nike

我正在开发一个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com