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.
| Property | Description |
|---|---|
title read-only | The title |
subtitle read-only | The subtitle |
body read-only | The body |
badge read-only | What to change the number on the icon to on delivery |
sound read-only | The sound played on delivery |
threadIdentifier read-only | The thread identifier for grouping |
userInfo read-only | Data that travels with the notification. For remote push notifications, this is the whole push payload |
Examples
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
UNMutableNotificationContent: write content yourselfUNNotificationRequest: content is read from the request