Created
January 31, 2018 12:34
-
-
Save 3257/e29a36c9ff47dded52329c6e5b5e9097 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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