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

Tasks

Display Information

Displayed Notification Buttons

Delivery Timing

Delivery Information

User Notification Activation Method

User Notification User Information

Properties

actionButtonTitle

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

@property (copy) NSString *actionButtonTitle
Discussion

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

Availability
  • Available in OS X v10.8 and later.
Declared In
NSUserNotification.h

activationType

Specifies what caused a user notification to occur. (read-only)

@property (readonly) NSUserNotificationActivationType activationType
Discussion

This property specifies why the user notification was sent to to the NSUserNotificationCenterDelegate method userNotificationCenter:didActivateNotification:. The supported values are described in ‚ÄúNSUserNotificationActivationType.‚ÄĚ

Availability
  • Available in OS X v10.8 and later.
Declared In
NSUserNotification.h

actualDeliveryDate

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

@property (readonly) 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 will be 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.

Availability
  • Available in OS X v10.8 and later.
Declared In
NSUserNotification.h

deliveryDate

Specifies when the notification should be delivered.

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

Availability
  • Available in OS X v10.8 and later.
Declared In
NSUserNotification.h

deliveryRepeatInterval

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

@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 will be 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.

Availability
  • Available in OS X v10.8 and later.
Declared In
NSUserNotification.h

deliveryTimeZone

Specify the time zone to interpret the delivery date in.

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

Availability
  • Available in OS X v10.8 and later.
Declared In
NSUserNotification.h

hasActionButton

Specifies whether the notification displays an action button.

@property BOOL hasActionButton
Discussion

Set to NO if the notification has no action button. This will be the case for notifications that are purely for informational purposes and have no user action.

The default value is YES.

Availability
  • Available in OS X v10.8 and later.
Declared In
NSUserNotification.h

informativeText

The body text of the notification.

@property (copy) NSString *informativeText
Discussion

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

Availability
  • Available in OS X v10.8 and later.
Declared In
NSUserNotification.h

otherButtonTitle

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

@property (copy) NSString *otherButtonTitle
Discussion

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

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

Availability
  • Available in OS X v10.8 and later.
Declared In
NSUserNotification.h

presented

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

@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 will be NO. It will be set to YES if the notification was presented according to user preferences.

Availability
  • Available in OS X v10.8 and later.
Declared In
NSUserNotification.h

remote

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

@property (readonly, getter=isRemote) BOOL remote
Discussion

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

Availability
  • Available in OS X v10.8 and later.
Declared In
NSUserNotification.h

soundName

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

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

Availability
  • Available in OS X v10.8 and later.
Declared In
NSUserNotification.h

subtitle

Specifies the subtitle of the notification.

@property (copy) NSString *subtitle
Discussion

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

Availability
  • Available in OS X v10.8 and later.
Declared In
NSUserNotification.h

title

Specifies the title of the notification.

@property (copy) NSString *title
Discussion

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

Availability
  • Available in OS X v10.8 and later.
Declared In
NSUserNotification.h

userInfo

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

@property (copy) NSDictionary *userInfo
Discussion

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

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

Availability
  • Available in OS X v10.8 and later.
Declared In
NSUserNotification.h

Constants

NSUserNotificationActivationType

These constants describe how the user notification was activated.

enum {
NSUserNotificationActivationTypeNone = 0,
NSUserNotificationActivationTypeContentsClicked = 1,
NSUserNotificationActivationTypeActionButtonClicked = 2
}
typedef NSInteger NSUserNotificationActivationType;
Constants
NSUserNotificationActivationTypeNone

The user did not interact with the notification alert.

Available in OS X v10.8 and later.

Declared in NSUserNotification.h.

NSUserNotificationActivationTypeContentsClicked

The user clicked on the contents of the notification alert.

Available in OS X v10.8 and later.

Declared in NSUserNotification.h.

NSUserNotificationActivationTypeActionButtonClicked

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

Available in OS X v10.8 and later.

Declared in NSUserNotification.h.

NSUserNotificationDefaultSoundName

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

NSString * const NSUserNotificationDefaultSoundName;
Constants
NSUserNotificationDefaultSoundName

The default notification sound.

Available in OS X v10.8 and later.

Declared in NSUserNotification.h.