Skip to content

Instantly share code, notes, and snippets.

@katopz
Created October 3, 2016 14:57
Show Gist options
  • Save katopz/30a0ae273d0d99617babc3c5c7067120 to your computer and use it in GitHub Desktop.
Save katopz/30a0ae273d0d99617babc3c5c7067120 to your computer and use it in GitHub Desktop.
iOS10 Push Notifications registerForRemoteNotifications
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