Skip to content

UNNotificationSettings ​

UNNotificationSettings represents this app's notification settings at a given moment: whether the user allows notifications, and whether each setting — sound, badge, lock screen, Notification Center, and so on — is on.

It only comes from getNotificationSettings() and is a snapshot: if the user later changes things in the system Settings app, this object doesn't change; fetch it again. There is no event when the user changes settings: changing settings means leaving the app, so fetch again in the active event on application when the user comes back.

All fields are read-only; writing to them throws TypeError. It is an ordinary JS value and doesn't inherit from NSObject.

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

Inheritance: UNNotificationSettings

Constructor ​

It can't be created with new. new UNNotificationSettings() throws TypeError:

Illegal constructor: UNNotificationSettings comes from UNUserNotificationCenter.getNotificationSettings()

Instance properties ​

All read-only.

PropertyDescription
authorizationStatus read-onlyWhether the user allows this app to send notifications
alertSetting read-onlyThe master switch for showing notifications
soundSetting read-onlySound
badgeSetting read-onlyThe number on the app icon
notificationCenterSetting read-onlyStaying in Notification Center
lockScreenSetting read-onlyShowing on the lock screen
carPlaySetting read-onlyShowing on CarPlay
criticalAlertSetting read-onlyCritical alerts
announcementSetting read-onlyRead aloud by Siri
timeSensitiveSetting read-onlyTime-sensitive notifications
scheduledDeliverySetting read-onlyScheduled summary
directMessagesSetting read-onlyBreaking through Focus as direct messages
alertStyle read-onlyHow notifications appear when the phone is unlocked
showPreviewsSetting read-onlyWhen the content of notifications is shown
providesAppNotificationSettings read-onlyWhether 'providesAppNotificationSettings' was included when requesting authorization

Three states ​

The eleven settings from alertSetting to directMessagesSetting all take one of these three values:

ValueMeaning
'enabled'On
'disabled'Off
'notSupported'This app doesn't have this setting: it was never requested, or the device doesn't support it

The values of each setting when authorization has never been requested are not verified in the simulator.

Examples ​

js
const center = UNUserNotificationCenter.currentNotificationCenter();
const settings = await center.getNotificationSettings();
console.log(settings.authorizationStatus, settings.soundSetting, settings.alertStyle);

Effect: It prints the authorization status, the state of the sound setting, and how notifications appear, such as authorized enabled banner. The specific values are not verified in the simulator.

Corresponding iOS API ​

ObjCJS
settings.authorizationStatus == UNAuthorizationStatusAuthorizedsettings.authorizationStatus === 'authorized'
settings.soundSetting == UNNotificationSettingEnabledsettings.soundSetting === 'enabled'

See also ​