OS X: How to get userinfo when an item from notification center clicked?

496 Views Asked by At

I want to do some specific action when app is activated because of clicking an remote notification item from Notification Center. Which delegate will give the userinfo?

-- Manoj

1

There are 1 best solutions below

7
On

I'm going to go ahead and assume you mean the UI notifications.

What you're looking for is NSUserNotification/NSUserNotificationCenter, as opposed to NSNotification/NSNotificationCenter, which are used to send messages to objects within your application.

You can construct an NSUserNotification with the userInfo property containing whatever information you'd like to receive later. You schedule the notification on NSUserNotificationCenter by accessing its defaultUserNotificationCenter and then either calling -scheduleNotification: or -deliverNotification: with the notification you created earlier. Lastly, the NSUserNotificationCenter has a delegate property, which you can assign to be whichever object you want to receive the notifications. That object will then have to implement one of the methods on the NSUserNotificationCenterDelegate protocol such as -userNotificationCenter:didDeliverNotification:.