iOS Swift,didRegisterForRemoteNotificationsWithDeviceToken

时间:2016-11-19 06:56:34

标签: ios swift notifications apple-push-notifications

我需要检查用户是否已授予通知权限,直到我知道只有在给出通知权限时才会调用didRegisterForRemoteNotificationsWithDeviceToken,但在某些设备中,无论权限如何,都会调用它给定与否。有人可以帮我解决如何检查许可状态的问题。

  即使我拒绝通知访问权限,

didRegisterForRemoteNotificationsWithDeviceToken也会被调用。

1 个答案:

答案 0 :(得分:0)

Swift 3.0和Xcode 8

UNUserNotificationCenter.current().delegate = self

UNUserNotificationCenter.current().requestAuthorization(options: [.badge, .sound, .alert], completionHandler: { (granted, error) in
                            if (granted)
                            {
                                UIApplication.shared.registerForRemoteNotifications()
                                //Allow Push Notification

                            }
                            else
                            {
                                //Don't Allow Push Notification
                            }
                        })