NSUserNotificationCenter Class Reference
| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/Foundation.framework |
| Availability | Available in OS X v10.8 and later. |
| Declared in | NSUserNotification.h |
Overview
The NSUserNotificationCenter class delivers user notifications to the user from applications or helper applications.
When a user notification’s delivery date has been reached, or it is manually delivered, the notification center may display the notification to the user. The user notification center reserves the right to decide if a delivered user notification is presented to the user. For example, it may suppress the notification if the application is already frontmost (the delegate can override this action). The application can check the result of this decision by examining the presented property of a delivered user notification.
NSUserNotification instances the NSUserNotificationCenter are tracking will be in one of two states: scheduled or delivered. A scheduled user notification has a deliveryDate. On that delivery date, the notification will move from being scheduled to being delivered. Note that the user notification may be displayed later than the delivery date depending on a number of factors.
A delivered user notification has an actualDeliveryDate. That is the date when it moved from being scheduled to delivered, or when it was manually delivered using the deliverNotification: method.
The application and the user notification center are both ultimately subject to the user’s preferences. If the user decides to hide all alerts from your application, the presented property will still behave as above, but the user will not see any animation or hear any sound.
The NSUserNotificationCenterDelegate provides more information about the delivered user notification and allows forcing the display of a user notification even if the application is frontmost.
Threading Information
The NSUserNotificationCenter class and the NSUserNotification class are both thread safe.
Tasks
Creating the Default User Notification Center
Managing the Scheduled Notification Queue
Managing the Delivered Notifications
-
– deliverNotification: -
deliveredNotificationsproperty -
– removeDeliveredNotification: -
– removeAllDeliveredNotifications
Getting and Setting the Delegate
-
delegateproperty
Properties
delegate
Specifies the notification center delegate.
Discussion
The delegate must conform to the NSUserNotificationCenterDelegate protocol.
Availability
- Available in OS X v10.8 and later.
Declared In
NSUserNotification.hdeliveredNotifications
An array of all user notifications delivered to the notification center. (read-only)
Discussion
The number of notifications the user actually sees in the user interface may be less than the size of this array.
Note that these may or may not have been actually presented to the user. See the presented property in the NSUserNotification class.
Availability
- Available in OS X v10.8 and later.
See Also
Declared In
NSUserNotification.hscheduledNotifications
Specifies an array of scheduled user notifications that have not yet been delivered.
Discussion
Newly scheduled notifications are added to the end of the array. You may also bulk-schedule notifications by setting this array. Bulk setting new scheduled notifications unschedules existing notifications.
Availability
- Available in OS X v10.8 and later.
Declared In
NSUserNotification.hClass Methods
defaultUserNotificationCenter
Returns the default user notification center.
Return Value
The default user notification object.
Availability
- Available in OS X v10.8 and later.
Declared In
NSUserNotification.hInstance Methods
deliverNotification:
Deliver the specified user notification.
Parameters
- notification
The user notification.
Discussion
The notification will be presented to the user (subject to the user’s preferences). The presented property of the NSUserNotification object will always be set to YES if a notification is delivered using this method.
Availability
- Available in OS X v10.8 and later.
Declared In
NSUserNotification.hremoveAllDeliveredNotifications
Remove all delivered user notifications from the user notification center.
Availability
- Available in OS X v10.8 and later.
See Also
Declared In
NSUserNotification.hremoveDeliveredNotification:
Remove a delivered user notification from the user notification center.
Parameters
- notification
The user notification.
Discussion
If the user notification is not in deliveredNotifications, nothing happens.
Availability
- Available in OS X v10.8 and later.
See Also
Declared In
NSUserNotification.hremoveScheduledNotification:
Removes the specified user notification for the scheduled notifications.
Parameters
- notification
The user notification.
Discussion
If the user notification’s deliveryDate occurs before the cancellation finishes, the notification may still be delivered.
If the notification is not in the scheduled list, nothing happens.
Availability
- Available in OS X v10.8 and later.
Declared In
NSUserNotification.hscheduleNotification:
Schedules the specified user notification.
Parameters
- notification
The user notification.
Discussion
Scheduled notifications are added to the end of the notification queue.
Availability
- Available in OS X v10.8 and later.
Declared In
NSUserNotification.h© 2012 Apple Inc. All Rights Reserved. (Last updated: 2012-07-23)