iOS Developer Library — Pre-Release

Developer

UIKit Framework Reference UIUserNotificationAction Class Reference

Options
Deployment Target:

On This Page
Language:

UIUserNotificationAction

A UIUserNotificationAction object represents a custom action that your app can perform in response to a remote or local notification. When a notification is delivered, the system displays a button for each custom action associated with the notification. Tapping a button launches your app (either in the foreground or background) and gives you a chance to perform the indicated action. You use this class to specify the text that is displayed in the button and the information your app needs to perform the corresponding action.

Typically, you create an instance of the UIMutableUserNotificationAction class instead of this class. You use the mutable object to configure the action and then call the setActions:forContext: method of UIMutableUserNotificationActionSettings to add the resulting actions to a group.

For each action you define, you must specify whether execution of that action requires the app to be running in the foreground or background. You can also specify whether the device must be unlocked or can remain locked while the action is performed. Unlocking the device may be necessary if the action involves reading or writing files that are encrypted on disk using the system’s data protection mechanism. When the user selects an action, the system puts your app into the appropriate mode and calls your app delegate’s application:handleActionWithIdentifier:forRemoteNotification:completionHandler: or application:handleActionWithIdentifier:forLocalNotification:completionHandler: method to perform the action.

Inheritance


Import Statement


Swift

import UIKit

Objective-C

@import UIKit;

Availability


Available in iOS 8.0 and later.
  • The mode in which to run the app when the action is performed. (read-only)

    Declaration

    Swift

    var activationMode: UIUserNotificationActivationMode { get }

    Objective-C

    @property(nonatomic, assign, readonly) UIUserNotificationActivationMode activationMode

    Discussion

    If the value in this property is UIUserNotificationActivationModeForeground, the value of the isAuthenticationRequired property is assumed to be YEStrue regardless of its actual value.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 8.0 and later.

  • A Boolean value indicating whether the user must unlock the device before the action is performed. (read-only)

    Declaration

    Swift

    var authenticationRequired: Bool { get }

    Objective-C

    @property(nonatomic, assign, readonly, getter=isAuthenticationRequired) BOOL authenticationRequired

    Discussion

    The value of this property is ignored and treated as a value of YEStrue when the value of the activationMode property is set to UIUserNotificationActivationModeForeground.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 8.0 and later.

  • A Boolean value indicating whether the action is destructive. (read-only)

    Declaration

    Swift

    var destructive: Bool { get }

    Objective-C

    @property(nonatomic, assign, readonly, getter=isDestructive) BOOL destructive

    Discussion

    Use this property to signal to the user whether the action causes destructive behavior to the user’s data or the app. When the value of this property is YEStrue, the system displays the corresponding button differently to indicate that the action is destructive.

    The default value of this property is NOfalse.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 8.0 and later.

  • Constants indicating whether the app should activate to the foreground or background.

    Declaration

    Swift

    enum UIUserNotificationActivationMode : UInt { case Foreground case Background }

    Objective-C

    typedef enum UIUserNotificationActivationMode : NSUInteger { UIUserNotificationActivationModeForeground, UIUserNotificationActivationModeBackground } UIUserNotificationActivationMode;

    Constants

    • Foreground

      UIUserNotificationActivationModeForeground

      Activate the app and put it in the foreground.

      Available in iOS 8.0 and later.

    • Background

      UIUserNotificationActivationModeBackground

      Activate the app and put it in the background. If the app is already in the foreground, it remains in the foreground.

      Available in iOS 8.0 and later.

    Import Statement

    Objective-C

    @import UIKit;

    Swift

    import UIKit

    Availability

    Available in iOS 8.0 and later.