Skip to content

Instantly share code, notes, and snippets.

@scott-lydon
Last active March 26, 2018 03:14
Show Gist options
  • Save scott-lydon/ab128d1b35d83315412e68ee4b51040a to your computer and use it in GitHub Desktop.
Save scott-lydon/ab128d1b35d83315412e68ee4b51040a to your computer and use it in GitHub Desktop.
try to register for push notifications
func getNotificationSettingsThenRegister() {
UNUserNotificationCenter.current().getNotificationSettings {
//This closure definition gets access to push notification settings
settings in
//Here we check if the user authorized push notifications
//If the user refused push notification auth, then this will exit early
guard settings.authorizationStatus == .authorized else {return}
//We pop the registration code onto the main queue as recommended by Apple
DispatchQueue.main.async {
//Here we attempt to register for remote push notifications
UIApplication.shared.registerForRemoteNotifications()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment