3

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.

user732274
  • 1,069
  • 1
  • 12
  • 28

1 Answers1

1

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.
markhunte
  • 6,805
  • 2
  • 25
  • 44
  • I have not used NotificationCenter. So have no code to hand. But also look at the constants: – markhunte Aug 18 '12 at 12:45
  • 1
    I know have built a test app. I see what you mean. Using activationType you can tell if the 'Show' button or Content id clicked. But nothing for the Close Button. Seems an odd oversight! – markhunte Aug 18 '12 at 15:33
  • 1
    Not sure why the down vote?.I feel my answer (Before I went to the trouble of writing code and testing.) was at least in the right direction.The documentation says for the 'userNotificationCenter:didActivateNotification:' "Sent to the delegate when a user clicks on a user notification presented by the user notification center". Which implies clicking anywhere gives you a constant. i.e either action buttons are clicked then the Alert is dismissed. Content click it is not.But it seems the Close button is not being included in the notifications. I wish people would add why they down vote. – markhunte Aug 18 '12 at 16:11
  • I suspect the reason for the downvote is that this method only allows you to determine whether (and react when it happens) the user has actively dismissed the notification rather than notice if it's still on the screen. On the other hand, I wouldn't say that is's clear from the question exactly what was being asked. +1 – Nate Chandler Aug 24 '12 at 17:35