Skip to content

UNMutableNotificationContent ​

UNMutableNotificationContent represents the content of a notification you write yourself: title, subtitle, body, badge, sound, group identifier, and data that travels with the notification.

Once the content is written, hand it to UNNotificationRequest.requestWithIdentifier() to create a request. The content is copied when the request is created; changing this object afterward does not change requests already created, and the same content object can be tweaked and used to create the next request.

It is a subclass of UNNotificationContent with the same fields; the difference is that the fields here are writable. It is a plain JS value and does not inherit from NSObject; it cannot be subclassed, and other fields cannot be added to it.

Install @nacrejs/user-notifications first; for how, see UNUserNotificationCenter, or Core and capability packages.

Inheritance: UNNotificationContent → UNMutableNotificationContent

Constructor ​

UNMutableNotificationContent()

Creates empty content: the string fields are all empty strings, with no badge and no sound.

Instance properties ​

All are readable and writable. Written values are converted according to each property's rules, and invalid ones throw TypeError.

PropertyDescription
titleThe title, a bold line
subtitleThe subtitle, a line below the title
bodyThe body
badgeWhat to set the number on the icon to on delivery
soundThe sound played on delivery
threadIdentifierThe group identifier
userInfoData that travels with the notification, not visible to the user

Examples ​

js
const content = new UNMutableNotificationContent();
content.title = 'Your order has shipped';
content.body = 'Expected to arrive tomorrow';
content.sound = UNNotificationSound.defaultSound;
content.userInfo = { orderId: 'A1024' };
const request = UNNotificationRequest.requestWithIdentifier('order-A1024', { content });
console.log(request.content.title);

Result: Prints Your order has shipped.

Corresponding iOS API ​

ObjCJS
[[UNMutableNotificationContent alloc] init]new UNMutableNotificationContent()
content.badge = @3 / content.badge = nilcontent.badge = 3 / content.badge = null
content.sound = UNNotificationSound.defaultSoundcontent.sound = UNNotificationSound.defaultSound
content.userInfo = @{ @"orderId": @"A1024" }content.userInfo = { orderId: 'A1024' }

See also ​