【发布时间】:2012-08-18 11:00:34
【问题描述】:
有没有办法确定某个NSUserNotification 是否仍在屏幕上或已被关闭?我还没有找到办法。
【问题讨论】:
标签: objective-c nsusernotification
有没有办法确定某个NSUserNotification 是否仍在屏幕上或已被关闭?我还没有找到办法。
【问题讨论】:
标签: objective-c nsusernotification
我认为你可以使用NSUserNotificationCenterDelegate_Protocol
它有 userNotificationCenter:didActivateNotification: 当用户点击用户通知中心呈现的用户通知时发送给代理。
但请记住,这还取决于所使用的通知类型。如果是“横幅”,那么它可能会在用户点击它之前消失。
因此,与代理一起,您还必须检查通知的类型以及它是否已提交。
更新: 我没有使用通知中心。所以手头没有代码。但也要看看常量:
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.
【讨论】: