0

我有这样的代码。

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

另外,我实现了 userNotificationCenter:shouldPresentNotification:。它工作正常。然而。当应用程序的窗口没有获得焦点时,不会调用此委托方法,并且通知始终存在。

有什么帮助吗?

4

1 回答 1

2

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

其次,在 的文档中-userNotificationCenter:shouldPresentNotification:,它指出:

userNotificationCenter:shouldPresentNotification:

当用户通知中心决定不展示您的通知时发送给委托人。

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

于 2014-01-10T10:41:41.190 回答