Objective c NSUserNotification状态

Objective c NSUserNotification状态,objective-c,nsusernotification,Objective C,Nsusernotification,是否有办法确定某个NSUserNotification是否仍在屏幕上或已被取消?我还没有找到一种方法来做这件事。我想你可以用 它具有userNotificationCenter:didActivateNotification: 当用户单击用户通知中心提供的用户通知时发送给代理 但请记住,这还取决于所使用的通知类型。如果是“横幅”,则在用户单击它之前,它可能会消失 因此,与委托一起,您还必须检查通知的类型以及通知是否已呈现 更新: 我没有用过NotificationCenter。因此,我们手头没有

是否有办法确定某个NSUserNotification是否仍在屏幕上或已被取消?我还没有找到一种方法来做这件事。

我想你可以用

它具有userNotificationCenter:didActivateNotification: 当用户单击用户通知中心提供的用户通知时发送给代理

但请记住,这还取决于所使用的通知类型。如果是“横幅”,则在用户单击它之前,它可能会消失

因此,与委托一起,您还必须检查通知的类型以及通知是否已呈现

更新:
我没有用过NotificationCenter。因此,我们手头没有代码。但也要看看这些常数:

NSUserNotificationActivationType
These constants describe how the user notification was activated.

enum {
NSUserNotificationActivationTypeNone = 0,
NSUserNotificationActivationTypeContentsClicked = 1,
NSUserNotificationActivationTypeActionButtonClicked = 2
}
typedef NSInteger NSUserNotificationActivationType;
Constants
NSUserNotificationActivationTypeNone
The user did not interact with the notification alert.
Available in OS X v10.8 and later.
Declared in NSUserNotification.h.
NSUserNotificationActivationTypeContentsClicked
The user clicked on the contents of the notification alert.
Available in OS X v10.8 and later.
Declared in NSUserNotification.h.
NSUserNotificationActivationTypeActionButtonClicked
The user clicked on the action button of the notification alert.
Available in OS X v10.8 and later.
Declared in NSUserNotification.h.

我没有用过NotificationCenter。因此,我们手头没有代码。但也看看常量:我知道你已经构建了一个测试应用程序。我明白你的意思。使用activationType,您可以判断是否单击了“显示”按钮或内容id。但“关闭”按钮没有显示任何内容。这似乎是一个奇怪的疏忽!我不知道为什么会投反对票。在我费心编写代码和测试之前,我已经找到了答案。至少在正确的方向上。文档中说“userNotificationCenter:didActivateNotification:”在用户单击用户通知中心提供的用户通知时发送给代理。这意味着单击任意位置会得到一个常量。i、 e单击任一操作按钮,然后解除警报。内容点击它不是。但似乎关闭按钮没有包含在通知中。我希望人们能补充一下为什么他们会投反对票。我怀疑投反对票的原因是,这种方法只允许您确定用户是否主动拒绝了通知,而不是通知是否仍在屏幕上,并在发生这种情况时做出反应。另一方面,我不会说,从问题中可以清楚地看出,到底问了什么+1.