UIUserNotificationSettings deprecated in iOS 10

Prav picture Prav · Sep 28, 2016 · Viewed 26.3k times · Source

I am looking for the alternate way of implementing UIUserNotificationSettings in iOS 10.

Apple documentation has given the below framework for the further usage. UNNotificationSettings in the link here.

Is there any one who can help me with the sample code to implement the below using the UNNotificationSettings instead of UIUserNotificationSettings

let notificationSettings = UIUserNotificationSettings(
        forTypes: [.Badge, .Sound, .Alert], categories: nil)
    application.registerUserNotificationSettings(notificationSettings)

Answer

Oleg Gordiichuk picture Oleg Gordiichuk · Sep 28, 2016

Registration of notification you should implement this code :

import UserNotifications

UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { 
 (granted, error) in
 //Parse errors and track state
}

This resource contains additional information.