Skip to content

Instantly share code, notes, and snippets.

@olivaresf
Last active July 17, 2020 07:27
Show Gist options
  • Save olivaresf/b57d9b1545e7e85e821a3febc8536f74 to your computer and use it in GitHub Desktop.
Save olivaresf/b57d9b1545e7e85e821a3febc8536f74 to your computer and use it in GitHub Desktop.
Example July 17
func requestAuthorization(completion: ((Bool, Error?) -> Void)? = nil) {
// enable local notifications (alarms in background)
let authorizationOptions: UNAuthorizationOptions
if #available(iOS 12.0, *) {
authorizationOptions = [.badge, .alert, .sound, .criticalAlert]
} else {
authorizationOptions = [.badge, .alert, .sound]
}
UNUserNotificationCenter.current().requestAuthorization(options: authorizationOptions) { (granted, error) in
// Enable or disable features based on authorization.
dispatchOnMain {
completion?(granted, error)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment