Skip to content

UNNotification ​

UNNotification represents a notification that has been delivered. Only the system provides it: from getDeliveredNotifications(), the notification event, and response.notification of the notificationclick event.

It is a read-only value: its fields can't be changed, and writing one throws TypeError. It is a plain JS value and doesn't inherit from NSObject.

You need to install @nacrejs/user-notifications first. For how, see UNUserNotificationCenter, or Core and capability packages.

Inheritance: UNNotification

Constructor ​

Can't be created with new. new UNNotification() throws TypeError:

Illegal constructor: UNNotification comes from the system (delivered notifications and the notification events)

Instance properties ​

PropertyDescription
date read-onlyWhen it was delivered
request read-onlyThe request it came from

Examples ​

js
const center = UNUserNotificationCenter.currentNotificationCenter();
center.addEventListener('notification', (event) => {
  const notification = event.notification;
  console.log(notification.request.identifier, notification.date.toISOString());
});

Effect (not verified in the simulator): When a notification arrives while the app is in the foreground, it prints the notification's identifier and delivery time.

Corresponding iOS API ​

ObjCJS
notification.date (NSDate)notification.date (Date)
notification.requestnotification.request

See also ​