Mac Developer Library

Developer

Foundation Framework Reference NSUserNotificationCenter Class Reference

Options
Deployment Target:

On This Page
Language:

NSUserNotificationCenter

Inheritance


Conforms To


Import Statement


Swift

import Foundation

Objective-C

@import Foundation;

Availability


Available in OS X v10.8 and later.

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.

  • Returns the default user notification center.

    Declaration

    Swift

    class func defaultUserNotificationCenter() -> NSUserNotificationCenter

    Objective-C

    + (NSUserNotificationCenter *)defaultUserNotificationCenter

    Return Value

    The default user notification object.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.8 and later.

  • Schedules the specified user notification.

    Declaration

    Swift

    func scheduleNotification(_ notification: NSUserNotification)

    Objective-C

    - (void)scheduleNotification:(NSUserNotification *)notification

    Parameters

    notification

    The user notification.

    Discussion

    Scheduled notifications are added to the end of the notification queue.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.8 and later.

  • Specifies an array of scheduled user notifications that have not yet been delivered.

    Declaration

    Swift

    var scheduledNotifications: [AnyObject]

    Objective-C

    @property(copy) NSArray *scheduledNotifications

    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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.8 and later.

  • Removes the specified user notification for the scheduled notifications.

    Declaration

    Swift

    func removeScheduledNotification(_ notification: NSUserNotification)

    Objective-C

    - (void)removeScheduledNotification:(NSUserNotification *)notification

    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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.8 and later.

  • delegate delegate Property

    Specifies the notification center delegate.

    Declaration

    Swift

    unowned(unsafe) var delegate: NSUserNotificationCenterDelegate?

    Objective-C

    @property(assign) id< NSUserNotificationCenterDelegate > delegate

    Discussion

    The delegate must conform to the NSUserNotificationCenterDelegate protocol.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.8 and later.