Class

UNNotificationAction

A task to perform in response to a delivered notification.

Declaration

class UNNotificationAction : NSObject

Overview

Use UNNotificationAction objects to define the actions that your app can perform in response to a delivered notification. You define the actions that your app supports. For example, a meeting app might define actions for accepting or rejecting a meeting invitation. The action object itself contains the title to display in an action button and the button's appearance. After creating action objects, add them to a UNNotificationCategory object and register your categories with the system.

For information on how to define actions and categories, see Declaring Your Actionable Notification Types.

Responding to the Selection of Actions

When the user selects one of your actions in response to a notification, the system notifies the delegate of the shared UNUserNotificationCenter object. Specifically, the system calls the userNotificationCenter(_:didReceive:withCompletionHandler:) method of your delegate object. The response object passed to your delegate includes the identifier string of the action that was selected, which you can use to perform the corresponding task.

For information on how to handle actions, see Handling Notifications and Notification-Related Actions.

Topics

Creating an Action

init(identifier: String, title: String, options: UNNotificationActionOptions = [])

Creates an action object with the specified title and options.

Getting the Action Information

var identifier: String

The unique string that your app uses to identify the action.

var title: String

The localized string to use as the title of the action.

Getting the Action Options

var options: UNNotificationActionOptions

The behaviors associated with the action.

struct UNNotificationActionOptions

The behaviors you can apply to an action.

Relationships

Inherits From

See Also

Notification Categories and User Actions

Declaring Your Actionable Notification Types

Differentiate your notifications and add action buttons to the notification interface.

class UNNotificationCategory

A type of notification that your app supports and the custom actions to display with it.

class UNTextInputNotificationAction

An action that can accept user-typed text.