3

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

4

1 回答 1

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.
于 2012-08-18T12:05:22.883 回答