Created
July 17, 2020 07:28
-
-
Save olivaresf/e8fc8da2f9413e2d3bffa0221e95c010 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func requestAuthorization(completion: @escaping (Result<Bool, Error>) -> Void) { | |
var authorizationOptions: UNAuthorizationOptions = [.badge, .alert, .sound] | |
if #available(iOS 12.0, *) { | |
authorizationOptions.insert(.criticalAlert) | |
} | |
let notificationCenter = UNUserNotificationCenter.current() | |
notificationCenter.requestAuthorization(options: authorizationOptions) { (granted, possibleError) in | |
guard possibleError == nil else { | |
completion(.failure(possibleError!)) | |
return | |
} | |
completion(.success(granted)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment