【问题标题】:Cocoa: Forcing an NSUserNotification while app is frontmostCocoa:在应用程序位于最前面时强制使用 NSUserNotification
【发布时间】:2012-08-19 14:47:53
【问题描述】:

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

用户通知中心保留决定是否 交付用户 通知被呈现给用户。例如,它可能会抑制 如果应用程序已经是最前面的通知(委托可以覆盖 这个动作)。

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

有什么想法吗?

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

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

但是什么也没发生。

【问题讨论】:

标签: cocoa delegates nsusernotification


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2015-10-30
    • 1970-01-01
    • 1970-01-01
    • 2012-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-04
    • 2014-09-15
    相关资源
    最近更新 更多