Skip to content

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 ​

UNNotificationResponseEvent()

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.

PropertyDescription
response read-onlyThe 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 ​

ObjectEvents
UNUserNotificationCenternotificationclick

It can't be canceled: cancelable is false, and preventDefault() has no effect.

Examples ​

js
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 ​

ObjCJS
userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:The notificationclick event
The response parameterevent.response

See also ​