Swift:用户接受或拒绝通知时的操作

Swift: Action if the user accepted or rejected notifications

我正在使用以下代码请求推送和本地通知权限:

let application = UIApplication.shared
let settings: UIUserNotificationSettings = UIUserNotificationSettings( types:  [.alert, .badge, .sound], categories: nil )

application.registerUserNotificationSettings( settings )
application.registerForRemoteNotifications()

在我采取行动之前,我需要等待用户接受或拒绝通知。我怎样才能做到这一点?

注意: Apple 已弃用我在下面给出的答案。请查看@ergunkocak 的回答

当用户授予或拒绝权限时,应用程序委托中的回调方法是 application(_:didRegister:),您应该使用该方法根据用户选择的权限设置执行特定操作。我建议阅读文档 here.

Swift AppDelegate.swift 中的 3 个:

func application(_ application: UIApplication, didRegister notificationSettings: UIUserNotificationSettings) {
    // Check here
}