UNMutableNotificationContent: sound property
The sound property is the sound played when the notification is delivered.
Value
A UNNotificationSound, or null.
- Readable and writable.
- The default is
null: silent. - Only
UNNotificationSound.defaultSound(the system's default notification sound) ornull(silent) can be written. - When the app is in the foreground, whether a delivered notification plays a sound also depends on whether
foregroundPresentationOptionsincludes'sound'. - The content is copied when a request is created. Changing this property after the request is created does not change requests already created.
- Only the app itself can change it; there is no change notification.
Invalid values
- Writing
nullorundefinedgivesnull. - Other values throw
TypeError:sound must be UNNotificationSound.defaultSound or null, got "default". - Writing the kind of sound read from a remotely pushed notification also throws:
sound must be UNNotificationSound.defaultSound or null, got a sound that came from a delivered notification.
Examples
js
const content = new UNMutableNotificationContent();
content.title = 'New message';
content.sound = UNNotificationSound.defaultSound;
console.log(content.sound === UNNotificationSound.defaultSound);Result: Prints true. A notification sent with this content plays the system's default notification sound when delivered (not verified in the simulator).
Corresponding iOS API
UNMutableNotificationContent.sound.
See also
UNNotificationContent: the read-only property of the same name on content that is read backUNNotificationRequest.requestWithIdentifier(): creating a request from content- This class belongs to the
@nacrejs/user-notificationspackage; for how to install it, see Install first