Skip to content

Instantly share code, notes, and snippets.

@3257
Created January 31, 2018 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 3257/e29a36c9ff47dded52329c6e5b5e9097 to your computer and use it in GitHub Desktop.
Save 3257/e29a36c9ff47dded52329c6e5b5e9097 to your computer and use it in GitHub Desktop.
func registerForPushNotifications() {
UNUserNotificationCenter.current().delegate = self
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) {
(granted, error) in
print("Permission granted: \(granted)")
// 1. Check if permission granted
guard granted else { return }
// 2. Attempt registration for remote notifications on the main thread
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment