Skip to content

UNNotificationPresentEvent ​

UNNotificationPresentEvent represents a notification arriving while the app is in the foreground.

The notification event of UNUserNotificationCenter is this class, and notification is the one that just arrived.

It belongs to the @nacrejs/user-notifications package; for installation, see UNUserNotificationCenter.

Inheritance: Event → UNNotificationPresentEvent

Constructor ​

UNNotificationPresentEvent()

Creates a UNNotificationPresentEvent. 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
notification read-onlyThe notification that just arrived

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
UNUserNotificationCenternotification

It can't be canceled: cancelable is false. How the notification is presented on screen is decided before the event is fired, by foregroundPresentationOptions.

Examples ​

js
const center = UNUserNotificationCenter.currentNotificationCenter();
center.addEventListener('notification', (e) => {
  console.log(e instanceof UNNotificationPresentEvent, e.notification.request.identifier);
});

Effect: when a notification arrives while the app is in the foreground, prints true and the notification's identifier. Not verified in the simulator.

Corresponding iOS API ​

ObjCJS
userNotificationCenter:willPresentNotification:withCompletionHandler:The notification event
The notification parameterevent.notification
completionHandler(options)foregroundPresentationOptions, set beforehand

See also ​