gpt4 book ai didi

macos - 当应用程序未获得焦点时,NSUserNotificationCenter 委托(delegate)不起作用

转载 作者:行者123 更新时间:2023-12-03 17:39:52 25 4
gpt4 key购买 nike

我有这样的代码。

[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
[[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self];

此外,我还实现了 userNotificationCenter:shouldPresentNotification:。效果很好。然而。当应用程序的窗口未聚焦时,不会调用此委托(delegate)方法,并且通知始终存在。

有什么帮助吗?

最佳答案

首先,您应该在发送 -deliverNotification: 消息之前设置委托(delegate)。如果不这样做,您的委托(delegate)方法可能不会被触发,即使它应该被触发。

第二,在 documentation for -userNotificationCenter:shouldPresentNotification: ,它指出:

userNotificationCenter:shouldPresentNotification:

Sent to the delegate when the user notification center has decided not to present your notification.

NSUserNotificationCenter 已决定显示您的通知时,您才会看到此方法被调用。如果它决定应该显示它,它就不会费心去询问。

关于macos - 当应用程序未获得焦点时,NSUserNotificationCenter 委托(delegate)不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20844497/

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