gpt4 book ai didi

Cocoa:当应用程序位于最前面时强制执行 NSUserNotification

转载 作者:行者123 更新时间:2023-12-03 16:13:47 24 4
gpt4 key购买 nike

相当简单,我有一个应用程序应该发送通知,但如果该应用程序位于最前面,它就不会这样做。来自 NSUserNotificationCenter 类引用:

The user notification center reserves the right to decide if a delivered user notification is presented to the user. For example, it may suppress the notification if the application is already frontmost (the delegate can override this action).

据我所知,它与 NSUserNotificationCenterDelegate 协议(protocol)引用中显示的 userNotificationCenter:shouldPresentNotification: 方法有关,但我不知道如何实现它。我已经将我的类设置为 NSUserNotificationCenterDelegate,所以不是这样。

有什么想法吗?

编辑:在我设置为 NSUserNotificationCenterDelegate 的类中,我使用它来尝试覆盖原始方法,如果应用程序位于最前面,则默认为 NO:

- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification {
return YES;
}

但是什么也没发生。

最佳答案

NSUserNotificationCenter *center = [NSUserNotificationCenter defaultUserNotificationCenter];[中心日程通知:通知];center.delegate = self;

  • (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)通知{返回是;}

关于Cocoa:当应用程序位于最前面时强制执行 NSUserNotification,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12102601/

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