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
的文档。