Created
October 3, 2016 14:57
-
-
Save katopz/30a0ae273d0d99617babc3c5c7067120 to your computer and use it in GitHub Desktop.
iOS10 Push Notifications registerForRemoteNotifications
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 application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { | |
if #available(iOS 10.0, *) { | |
// iOS 10+ | |
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { (granted, error) in | |
print("Notifications access granted: \(granted.description)") | |
} | |
application.registerForRemoteNotifications() | |
} else { | |
// iOS 8, 9 | |
let types: UIUserNotificationType = [.alert, .badge, .sound] | |
let settings = UIUserNotificationSettings(types: types, categories: nil) | |
application.registerUserNotificationSettings(settings) | |
application.registerForRemoteNotifications() | |
} | |
return true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment