Reputation: 883
How can I check UNUserNotificationCenter for current authorization status in iOS 11? I've been looking for a while and found some code but it's not in swift 3 and some of functions were deprecated in iOS 10. Can anyone help?
Upvotes: 22
Views: 15445
Reputation: 821
When getting the notification authorization status, there are actually three states it can be in, i.e.
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
Upvotes: 16