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.
| Property | Description |
|---|---|
authorizationStatus read-only | Whether the user allows this app to send notifications |
alertSetting read-only | The master switch for showing notifications |
soundSetting read-only | Sound |
badgeSetting read-only | The number on the app icon |
notificationCenterSetting read-only | Staying in Notification Center |
lockScreenSetting read-only | Showing on the lock screen |
carPlaySetting read-only | Showing on CarPlay |
criticalAlertSetting read-only | Critical alerts |
announcementSetting read-only | Read aloud by Siri |
timeSensitiveSetting read-only | Time-sensitive notifications |
scheduledDeliverySetting read-only | Scheduled summary |
directMessagesSetting read-only | Breaking through Focus as direct messages |
alertStyle read-only | How notifications appear when the phone is unlocked |
showPreviewsSetting read-only | When the content of notifications is shown |
providesAppNotificationSettings read-only | Whether 'providesAppNotificationSettings' was included when requesting authorization |
Three states
The eleven settings from alertSetting to directMessagesSetting all take one of these three values:
| Value | Meaning |
|---|---|
'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
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
| ObjC | JS |
|---|---|
settings.authorizationStatus == UNAuthorizationStatusAuthorized | settings.authorizationStatus === 'authorized' |
settings.soundSetting == UNNotificationSettingEnabled | settings.soundSetting === 'enabled' |