user notification

User Notifications work with your apps to let you know when something has changed. For example, you can see when there’s upcoming appointments in Calendar or incoming email in Mail. Each app displays these notifications as a banner, alert, or badge.

How to display User Notification as small popup message?

How to display a User Notification in the Notification Center?

user notification

Displaying such a user notification is quite easy. Foundation Framework provides NSUserNotification and NSUserNotificationCenter class. The following code shows a usage example:

This code should display a notification in the Notification Center. But it’s not displayed by default as a popup message. To display it we must to implement NSUserNotificationCenterDelegate protocol. And the method we need is called userNotificationCenter:shouldPresentNotification:. Here is an example.

It’s quite easy.

And finally we need to set a class a delegate of the NSUserNotificationCenter as self. A good method for that is applicationDidFinishLaunching: in AppDelegate class:

You can add action button to notification as described in NSUserNotification header
Also you can set deliveryDate and other schedule properties