2016-11-19 78 views
0

我需要檢查用戶是否已經授予通知權限,直到日期我知道didRegisterForRemoteNotificationsWithDeviceToken只有在獲得通知權限時纔會被調用,但在某些設備中,它會被調用而不管權限是否給出。有人可以幫助我瞭解如何檢查權限狀態。iOS Swift,didRegisterForRemoteNotificationsWithDeviceToken

didRegisterForRemoteNotificationsWithDeviceToken即使在我拒絕通知訪問的權限時也會被調用。

回答

0
夫特

3.0和8的Xcode

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 
          } 
         }) 
相關問題