Mac Developer Library

Developer

Foundation Framework Reference NSUserNotificationCenterDelegate Protocol Reference

Options
Deployment Target:

On This Page
Language:

NSUserNotificationCenterDelegate

Inheritance


Not Applicable

Conforms To


Import Statement


Swift

import Foundation

Objective-C

@import Foundation;

Availability


Available in OS X v10.8 and later.

The NSUserNotificationCenterDelegate protocol allows customization of the behavior of the default NSUserNotificationCenter instance.

  • Sent to the delegate when a notification delivery date has arrived.

    Declaration

    Swift

    optional func userNotificationCenter(_ center: NSUserNotificationCenter, didDeliverNotification notification: NSUserNotification)

    Objective-C

    - (void)userNotificationCenter:(NSUserNotificationCenter *)center didDeliverNotification:(NSUserNotification *)notification

    Parameters

    center

    The user notification center.

    notification

    The user notification object.

    Discussion

    This method is always called, regardless of your application state and even if you deliver the user notification yourself using deliverNotification:.

    This delegate method is invoked before the userNotificationCenter:shouldPresentNotification: delegate method.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.8 and later.

  • Sent to the delegate when a user clicks on a user notification presented by the user notification center.

    Declaration

    Swift

    optional func userNotificationCenter(_ center: NSUserNotificationCenter, didActivateNotification notification: NSUserNotification)

    Objective-C

    - (void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification

    Parameters

    center

    The user notification center.

    notification

    The user notification object.

    Discussion

    This would be a good time to take action in response to user interacting with a specific notification.

    To take an action when your application is launched as a result of a user clicking on a notification, be sure to implement the applicationDidFinishLaunching: method in the application class that implements the NSApplicationDelegate Protocol protocol. The notification parameter to that method has a userInfo dictionary, and if that dictionary has the NSApplicationLaunchUserNotificationKey key. The value of that key is the NSUserNotification object that caused the application to launch. The NSUserNotification object is delivered to the NSApplication delegate because that message will be sent before your application has a chance to set a delegate for the NSUserNotificationCenter.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.8 and later.

  • Sent to the delegate when the user notification center has decided not to present your notification.

    Declaration

    Swift

    optional func userNotificationCenter(_ center: NSUserNotificationCenter, shouldPresentNotification notification: NSUserNotification) -> Bool

    Objective-C

    - (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification

    Parameters

    center

    The user notification center.

    notification

    The user notification object.

    Return Value

    YEStrue if the user notification should be displayed regardless; NOfalse otherwise.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.8 and later.