Skip to content

Instantly share code, notes, and snippets.

@scott-lydon
Last active March 26, 2018 03:15
Show Gist options
  • Save scott-lydon/abe2864f0f80d9d9eb3fd9a662952c92 to your computer and use it in GitHub Desktop.
Save scott-lydon/abe2864f0f80d9d9eb3fd9a662952c92 to your computer and use it in GitHub Desktop.
RegisterForRemoteNotifications function
//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