How to get notification authorization status in swift 3?

Okay I found it:

let center = UNUserNotificationCenter.current()
center.getNotificationSettings { (settings) in
    if(settings.authorizationStatus == .authorized)
    {
        print("Push authorized")
    }
    else
    {
        print("Push not authorized")
    }
}

code by: Kuba


When getting the notification authorization status, there are actually three states it can be in, i.e.

  • authorized
  • denied
  • non-determined

A straightforward way to check these is with a switch-case where .authorized, .denied, and .nonDetermined are enums in UNAuthorizationStatus

UNUserNotificationCenter.current().getNotificationSettings { (settings) in
    print("Checking notification status")

    switch settings.authorizationStatus {
    case .authorized:
        print("authorized")

    case .denied:
        print("denied")

    case .notDetermined:
        print("notDetermined")

    }
}

Description of UNAuthorizationStatus can be found here in Apple's docs https://developer.apple.com/documentation/usernotifications/unauthorizationstatus