NSUserNotification状态

时间:2012-08-18 11:00:35

标签: objective-c nsusernotification

有没有办法确定某个NSUserNotification是否仍在屏幕上或已被解雇?我还没有办法做到这一点。

1 个答案:

答案 0 :(得分:1)

我认为你可以使用NSUserNotificationCenterDelegate_Protocol

它有 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.