Mac Developer Library

Developer

Foundation Framework Reference NSUserNotification Class Reference

Options
Deployment Target:

On This Page
Language:

NSUserNotification

The NSUserNotification class is used to configure a notification that is scheduled for display by the NSUserNotificationCenter class.

The NSUserNotification object not only configures the notification, when the notification is delivered information about when the notification was actually presented to the user (if at all) and other details are provided in the notification object. User applications can create NSUserNotification objects and register them with the NSUserNotificationCenter object to notify the user when an application requires attention.

See NSUserNotificationCenter Class Reference for more information.

Threading Information

The NSUserNotificationCenter class and the NSUserNotification class are both thread safe.

Inheritance


Conforms To


Import Statement


Swift

import Foundation

Objective-C

@import Foundation;

Availability


Available in OS X v10.8 and later.
  • title title Property

    Specifies the title of the notification.

    Declaration

    Swift

    var title: String?

    Objective-C

    @property(copy) NSString *title

    Discussion

    This value should be localized because it is presented to the user. The string is truncated to a length appropriate for display and the property is modified to reflect the truncation.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.8 and later.

  • subtitle subtitle Property

    Specifies the subtitle of the notification.

    Declaration

    Swift

    var subtitle: String?

    Objective-C

    @property(copy) NSString *subtitle

    Discussion

    This value should be localized as it is presented to the user. The string is truncated to a length appropriate for display and the property is modified to reflect the truncation.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.8 and later.

  • The body text of the notification.

    Declaration

    Swift

    var informativeText: String?

    Objective-C

    @property(copy) NSString *informativeText

    Discussion

    This value should be localized as it is presented to the user. The string is truncated to a length appropriate for display and the property is modified to reflect the truncation.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.8 and later.

    See Also

    title
    subtitle

  • Image shown in the content of the notification.

    Declaration

    Swift

    @NSCopying var contentImage: NSImage?

    Objective-C

    @property(copy) NSImage *contentImage

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.9 and later.

  • Identifier for a notification.

    Declaration

    Swift

    var identifier: String?

    Objective-C

    @property(copy) NSString *identifier

    Discussion

    This identifier is unique to a notification. A notification delivered with the same identifier as an existing notification will replace that notification, rather then display a new one.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.9 and later.

  • response response Property

    The response with which the user responded to a notification. (read-only)

    Declaration

    Swift

    @NSCopying var response: NSAttributedString? { get }

    Objective-C

    @property(readonly, copy) NSAttributedString *response

    Discussion

    When the user responds to a notification, the NSUserNotificationCenterDelegate method userNotificationCenter:didActivateNotification: is called with the notification, the activationType property set to NSUserNotificationActivationTypeReplied, and this property is set with the user’s response.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.9 and later.

  • Optional placeholder string for inline reply field.

    Declaration

    Swift

    var responsePlaceholder: String?

    Objective-C

    @property(copy) NSString *responsePlaceholder

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.9 and later.

  • A Boolean value that specifies whether the notification displays an action button.

    Declaration

    Swift

    var hasActionButton: Bool

    Objective-C

    @property BOOL hasActionButton

    Discussion

    Set to NOfalse if the notification has no action button. This is the case for notifications that are purely for information and have no user action. The default value is YEStrue.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.8 and later.

  • Specifies the title of the action button displayed in the notification.

    Declaration

    Swift

    var actionButtonTitle: String

    Objective-C

    @property(copy) NSString *actionButtonTitle

    Discussion

    This value should be localized as it is presented to the user. The string is truncated to a length appropriate for display and the property is modified to reflect the truncation.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.8 and later.

  • Specifies a custom title for the close button in an alert-style notification.

    Declaration

    Swift

    var otherButtonTitle: String

    Objective-C

    @property(copy) NSString *otherButtonTitle

    Discussion

    This value should be localized as it is presented to the user. The string is truncated to a length appropriate for display and the property is modified to reflect the truncation.

    An empty string will cause the default localized text to be used. A nil value is invalid.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.8 and later.

  • A Boolean value that specifies whether the notification displays a reply button.

    Declaration

    Swift

    var hasReplyButton: Bool

    Objective-C

    @property BOOL hasReplyButton

    Discussion

    Set to YEStrue if the notification has a reply button. The default value is NOfalse. If this property and hasActionButton are both YEStrue, the reply button is shown.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.9 and later.

  • Specifies when the notification should be delivered.

    Declaration

    Swift

    @NSCopying var deliveryDate: NSDate?

    Objective-C

    @property(copy) NSDate *deliveryDate

    Discussion

    The delivery date is specified in an absolute time.

    After a notification is delivered, it may be presented to the user.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.8 and later.

  • The date this notification was actually delivered. (read-only)

    Declaration

    Swift

    @NSCopying var actualDeliveryDate: NSDate? { get }

    Objective-C

    @property(readonly, copy) NSDate *actualDeliveryDate

    Discussion

    The notification center will set this value if a notification is put in the scheduled list and the delivery time arrives.

    If the notification is delivered directly using the deliverNotification: method of the NSUserNotificationCenter class, this value is set to the deliveryDate value. If the deliveryDate value nil this value is set to the current date.

    This value is used to sort the list of notifications in the user interface.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.8 and later.

  • Specifies the date components that control how often a user notification is repeated.

    Declaration

    Swift

    @NSCopying var deliveryRepeatInterval: NSDateComponents?

    Objective-C

    @property(copy) NSDateComponents *deliveryRepeatInterval

    Discussion

    This value may be nil if the notification should not repeat.

    The date component values are relative to the date the notification was delivered.

    If the calendar value of the deliveryRepeatInterval is nil, the current calendar is used to calculate the repeat interval. For example, if a notification should repeat every hour, set the hour property of the deliveryRepeatInterval to 1.

    This value is ignored unless the user notification is scheduled with the NSUserNotificationCenter object.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.8 and later.

  • Specify the time zone to interpret the delivery date in.

    Declaration

    Swift

    @NSCopying var deliveryTimeZone: NSTimeZone?

    Objective-C

    @property(copy) NSTimeZone *deliveryTimeZone

    Discussion

    If this value is nil and the user switches time zones, the notification center will adjust the time of presentation to account for the time zone change.

    If a notification should be delivered at a time in a specific time zone (regardless of whether the user switches time zones), set this value to the specific time zone, for example the current time zone.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.8 and later.

  • presented presented Property

    Specifies whether the user notification has been presented. (read-only)

    Declaration

    Swift

    var presented: Bool { get }

    Objective-C

    @property(readonly, getter=isPresented) BOOL presented

    Discussion

    In some cases, for example when your application is frontmost, the notification center may decide not to actually present a delivered notification. In that case, the value of this property is NOfalse. It is set to YEStrue if the notification was presented according to user preferences.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.8 and later.

  • remote remote Property

    Specifies whether the remote was generated by a push notification. (read-only)

    Declaration

    Swift

    var remote: Bool { get }

    Objective-C

    @property(readonly, getter=isRemote) BOOL remote

    Discussion

    If this property is YEStrue then the user notification was generated by a push notification (that is, remotely); if NOfalse it was generated locally.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.8 and later.

  • soundName soundName Property

    Specifies the name of the sound to play when the notification is delivered.

    Declaration

    Swift

    var soundName: String?

    Objective-C

    @property(copy) NSString *soundName

    Discussion

    Passing the NSUserNotificationDefaultSoundName constant causes the default notification center sound to be played.

    A value of nil means no sound is played.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.8 and later.

  • userInfo userInfo Property

    Application-specific user info that can be attached to the notification.

    Declaration

    Swift

    var userInfo: [NSObject : AnyObject]?

    Objective-C

    @property(copy) NSDictionary *userInfo

    Discussion

    All items must be property list types or an exception is thrown.

    The userInfo content must be of reasonable serialized size (less than 1KB) or an exception is thrown.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.8 and later.

  • These constants describe how the user notification was activated.

    Declaration

    Swift

    enum NSUserNotificationActivationType : Int { case None case ContentsClicked case ActionButtonClicked case Replied case AdditionalActionClicked }

    Objective-C

    typedef : enum NSInteger { NSUserNotificationActivationTypeNone = 0, NSUserNotificationActivationTypeContentsClicked = 1, NSUserNotificationActivationTypeActionButtonClicked = 2 NSUserNotificationActivationTypeReplied = 3, NSUserNotificationActivationTypeAdditionalActionClicked = 4 } NSUserNotificationActivationType;

    Constants

    • None

      NSUserNotificationActivationTypeNone

      The user did not interact with the notification alert.

      Available in OS X v10.8 and later.

    • ContentsClicked

      NSUserNotificationActivationTypeContentsClicked

      The user clicked on the contents of the notification alert.

      Available in OS X v10.8 and later.

    • ActionButtonClicked

      NSUserNotificationActivationTypeActionButtonClicked

      The user clicked on the action button of the notification alert.

      Available in OS X v10.8 and later.

    • Replied

      NSUserNotificationActivationTypeReplied

      The user replied to the notification.

      Available in OS X v10.9 and later.

    • AdditionalActionClicked

      NSUserNotificationActivationTypeAdditionalActionClicked

      The user clicked on the additional action button of the notification alert.

      Available in OS X v10.10 and later.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.8 and later.

  • The default sound played by the user notification center for this notification.

    Declaration

    Swift

    let NSUserNotificationDefaultSoundName: NSString!

    Objective-C

    NSString * const NSUserNotificationDefaultSoundName;

    Constants

    • NSUserNotificationDefaultSoundName

      NSUserNotificationDefaultSoundName

      The default notification sound.

      Available in OS X v10.8 and later.