简体   繁体   中英

NSUserNotification state

Is there a way to determine if a certain NSUserNotification is still on screen or it has been dismissed? I haven't found a way to do this.

I think you could use NSUserNotificationCenterDelegate_Protocol

It has userNotificationCenter:didActivateNotification: Sent to the delegate when a user clicks on a user notification presented by the user notification center.

But remember it also depends on what type of notification is being used. if 'Banners' then it may go away before the user clicks it.

So in conjunction to the delegate, you would have to also check the type of notification and if it was Presented.

Update: I have not used NotificationCenter. So have no code to hand. But also look atthe constants:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM