Last active
March 26, 2018 03:14
-
-
Save scott-lydon/ab128d1b35d83315412e68ee4b51040a to your computer and use it in GitHub Desktop.
try to register for push notifications
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 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