Home > Enterprise >  How to check if the "Time Sensitive Notifications" permission has been granted or revoked
How to check if the "Time Sensitive Notifications" permission has been granted or revoked

Time:10-18

iOS 15 's "Time Sensitive Notifications" is normally granted by default when user consents to notifications, but may be revoked by the user later, especially because iOS has a habit of asking the user if they want to do so whenever a Time Sensitive Notification shows up.

As a developer, we can easily check if the main notification permission is enabled for our app. But is it possible for us to check if the "Time Sensitive Notifications" permission is granted or revoked programmatically?

CodePudding user response:

You can do it with the getNotificationSettings method, for a completion handler way of doing it .

@available(iOS 15.0, *)
func getTimeSnsitiveStatus(result : @escaping (Bool) -> Void) {
    UNUserNotificationCenter.current().getNotificationSettings { settings in
        result(settings.timeSensitiveSetting == .enabled)
    }
}

or notificationSettings() for a concurrent setup.

@available(iOS 15.0, *)
func getTimeSnsitiveStatus() async -> Bool {
    return await UNUserNotificationCenter.current().notificationSettings().timeSensitiveSetting == .enabled
}
  • Related