2

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

Lucas Derraugh
  • 6,929
  • 3
  • 27
  • 43
ManojMarathayil
  • 712
  • 11
  • 28
  • Are you interested in an NSUserNotification or NSNotification? The former is the UI element that displays in the top right of your screen, the latter is for internal messaging in the app. – Lucas Derraugh Aug 13 '15 at 02:41

1 Answers1

0

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:.

Lucas Derraugh
  • 6,929
  • 3
  • 27
  • 43
  • Thanks Lucas. You are correct, I am looking for the UI element. But, the notification is delivered by APNs and it is showing in notification center on the right side. I want to open a particular view with information related to the userinfo part of this remote push notification. – ManojMarathayil Aug 13 '15 at 03:01
  • @Manoj Could you elaborate on that, what do you mean by 'opening a particular view'? – Lucas Derraugh Aug 13 '15 at 03:03
  • in my case, I am working with a mail client. I receive a notification for new mail, this will be displayed in list of notifications, when user clicks this i want to display the email content. Here the information required for displaying isn available in the userinfo as payload part of APNs. – ManojMarathayil Aug 13 '15 at 03:06
  • in case of iOS, didreceiveremotenotification is fired when app became active when we tap a notification – ManojMarathayil Aug 13 '15 at 03:07
  • Not sure if I quite get your exact use case, but on Mac OS, remote notifications can be received via the NSApplicationDelegate with -application:didReceiveRemoteNotification: https://developer.apple.com/library/mac/documentation/Cocoa/Reference/NSApplicationDelegate_Protocol/#//apple_ref/occ/intfm/NSApplicationDelegate/application:didReceiveRemoteNotification: – Lucas Derraugh Aug 13 '15 at 03:13
  • application:didReceiveRemoteNotification is called when the notification in received by the OS(if app is running), not when user clicks it. I want to act when user clicks on it from Notification Center – ManojMarathayil Aug 13 '15 at 03:15
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/86844/discussion-between-lucas-derraugh-and-manoj). – Lucas Derraugh Aug 13 '15 at 03:23