Last active
March 26, 2018 03:15
-
-
Save scott-lydon/abe2864f0f80d9d9eb3fd9a662952c92 to your computer and use it in GitHub Desktop.
RegisterForRemoteNotifications function
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
//Here starts the function definition and scope | |
func registerForPushNotifications() { | |
//Here we are creating a notifCenter reference for shorter lines of code | |
let notifCenter = UNUserNotificationCenter.current() | |
//Here we access the requestAuthorization method that lives on the | |
//UNUserNotificationCenter. It takes an array of options of an enum type | |
//and a closure as arguments. | |
notifCenter.requestAuthorization(options: [.alert, .sound, .badge]) { | |
//Here are two values that we have access to in the closure definition | |
//Access Granted (Bool) is true if the user gave permission to use push | |
//notifications. | |
accessGranted, error in | |
//Call the other function we defined | |
getNotificationSettingsThenRegister() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment