Skip to content

Instantly share code, notes, and snippets.

@olivaresf
Created July 17, 2020 07:28
Show Gist options
  • Save olivaresf/e8fc8da2f9413e2d3bffa0221e95c010 to your computer and use it in GitHub Desktop.
Save olivaresf/e8fc8da2f9413e2d3bffa0221e95c010 to your computer and use it in GitHub Desktop.
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