Skip to content

UNNotificationContent ​

UNNotificationContent represents the read-only content of a notification, read from a request's content, including those of delivered notifications and remote push notifications.

Its fields are the same as UNMutableNotificationContent, and none are writable: assigning to a field throws TypeError, such as title is read-only. To write content yourself, use UNMutableNotificationContent.

Content you read can be handed to requestWithIdentifier() again to create a new request, unless it carries a sound that isn't the default; see sound.

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: UNNotificationContent. Its subclass is UNMutableNotificationContent.

Constructor ​

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

Illegal constructor: UNNotificationContent is read from a request or a notification; write content with new UNMutableNotificationContent()

Instance properties ​

All read-only.

PropertyDescription
title read-onlyThe title
subtitle read-onlyThe subtitle
body read-onlyThe body
badge read-onlyWhat to change the number on the icon to on delivery
sound read-onlyThe sound played on delivery
threadIdentifier read-onlyThe thread identifier for grouping
userInfo read-onlyData that travels with the notification. For remote push notifications, this is the whole push payload

Examples ​

js
const center = UNUserNotificationCenter.currentNotificationCenter();
const delivered = await center.getDeliveredNotifications();
for (const notification of delivered) {
  const content = notification.request.content;
  console.log(content.title, content.body);
}

Effect: Prints one line with the title and body for each of this app's notifications in Notification Center. Not verified in the simulator.

Corresponding iOS API ​

UNNotificationContent. Each field has the same name as the ObjC property.

See also ​