Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/116.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Swift:用户接受或拒绝通知时的操作_Ios_Swift_Nsusernotification - Fatal编程技术网

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

Ios Swift:用户接受或拒绝通知时的操作,ios,swift,nsusernotification,Ios,Swift,Nsusernotification,我正在使用以下代码请求推送和本地通知权限: let application = UIApplication.shared let settings: UIUserNotificationSettings = UIUserNotificationSettings( types: [.alert, .badge, .sound], categories: nil ) application.registerUserNotificationSettings( settings ) applicat

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

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

application.registerUserNotificationSettings( settings )
application.registerForRemoteNotifications()

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

注意:苹果已经不赞成我下面给出的答案。请参阅@ergunkocak的答案


当用户授予或拒绝了权限时,应用程序委托中的回调方法是
application(\uquo;didRegister:)
,这是根据用户选择的权限设置采取特定操作时应使用的方法。我建议您阅读AppDelegate.Swift中的文档

Swift 3:

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

请参阅
UIApplicationLegate
的文档。