我使用以下代码请求推送和本地通知权限:
let application = UIApplication.shared
let settings: UIUserNotificationSettings = UIUserNotificationSettings( types: [.alert, .badge, .sound], categories: nil )
application.registerUserNotificationSettings( settings )
application.registerForRemoteNotifications()
在采取行动之前,我需要等待用户接受或拒绝通知。我怎样才能做到这一点?
答案 0 :(得分:3)
注意: Apple已经弃用了我在下面给出的答案。请参阅@ ergunkocak的回答
当用户授予或拒绝权限时,应用代理中的回调方法为application(_:didRegister:)
,这是您应根据用户选择的权限设置采取特定操作的方法。我建议阅读文档here.
答案 1 :(得分:2)
AppDelegate.swift中的Swift 3:
func application(_ application: UIApplication, didRegister notificationSettings: UIUserNotificationSettings) {
// Check here
}