UNNotificationResponseEvent
UNNotificationResponseEvent represents the user tapping a notification.
The notificationclick event of UNUserNotificationCenter is this class, and response is the user's action.
It belongs to the @nacrejs/user-notifications package; for installation, see UNUserNotificationCenter.
Inheritance: Event → UNNotificationResponseEvent
Constructor
Creates a UNNotificationResponseEvent. The runtime creates one itself when it fires the events below; app code can use it to build an event object and fire it with dispatchEvent() to try out a listener.
Instance properties
Also inherits the properties of Event; the most commonly used are type and target. The properties below are read-only; assigning to them throws TypeError.
| Property | Description |
|---|---|
response read-only | The user's action |
These properties live on the prototype, not on the event object itself: Object.keys(event) and { ...event } don't include them, so read them one by one. See Events with fields.
Events that use this class
| Object | Events |
|---|---|
UNUserNotificationCenter | notificationclick |
It can't be canceled: cancelable is false, and preventDefault() has no effect.
Examples
const center = UNUserNotificationCenter.currentNotificationCenter();
center.addEventListener('notificationclick', (e) => {
console.log(e instanceof UNNotificationResponseEvent, e.response.actionIdentifier);
});Effect: when the user taps a notification, prints true and the action identifier. Not verified in the simulator.
Corresponding iOS API
| ObjC | JS |
|---|---|
userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler: | The notificationclick event |
The response parameter | event.response |
See also
UNUserNotificationCenter: the object that fires this eventUNNotificationResponse