A task to perform in response to a delivered notification.
- iOS 10.0+
- watchOS 3.0+
UNNotification object represents a task that your app can perform in response to a delivered notification. You can define custom actions for each type of notification that your app supports. The action object itself contains information about how to display that action onscreen. When the user selects that action, the system forwards the action’s
identifier string to your app so that you can perform the corresponding task.
Always create instances of this class using the
init(identifier: method. After creating action objects, associate them with a
UNNotification object to define your app’s notification types. A notification can display up to four actions onscreen at once, and in some cases may display only two of those actions.
Responding to the Selection of Actions
You respond to the user selection of an action using the
user method of the shared
UNUser object’s delegate. When the user selects an action, the system calls that method and passes it a
UNNotification object that includes the identifier string of the action that the user selected. Use that identifier string to determine which action was selected and then perform whatever app-specific task is appropriate for that action.
For more information about handling actions, see