2016-11-08 74 views
0

我的應用程序需要這些權限如何推遲[權限請求警報]?

  • 通知
  • GPS
  • 照片

照片許可請求當用戶打開畫廊,但前兩個權限顯示應用程序與應用程序發射,我可以讓GPS作爲第一個要求的權限,但我想推遲通知對話到另一個屏幕,如何做到這一點?

這個library似乎不允許這個 有什麼建議嗎?

let notificationTypes : UIUserNotificationType = [UIUserNotificationType.Alert,UIUserNotificationType.Badge,UIUserNotificationType.Sound] 
let notificationSettings = UIUserNotificationSettings(forTypes: notificationTypes, categories: nil) 

application.registerForRemoteNotifications() 
application.registerUserNotificationSettings(notificationSettings) 
+1

1.您在AppDelegate中註冊的通知主叫,所以它肯定會要求啓動許可。 – Wolverine

+1

2.對於GPS,當您嘗試獲取位置時,它會詢問該許可。如果你在考慮第二個控制器的位置,那麼它可以完成,但如果你在AppDelegate中獲得位置,恐怕它會在應用程序啓動時提出要求。 – Wolverine

+1

嘗試在AppDelegate中創建一個方法。並調用該方法當你想顯示權限警告 – Wolverine

回答

0

感謝,這解決了對我來說,...

從應用委託

let notificationTypes : UIUserNotificationType = [UIUserNotificationType.Alert,UIUserNotificationType.Badge,UIUserNotificationType.Sound] 
    let notificationSettings = UIUserNotificationSettings(forTypes: notificationTypes, categories: nil) 
    application.registerForRemoteNotifications() 
    application.registerUserNotificationSettings(notificationSettings) 

調用從另一個類

let notificationTypes : UIUserNotificationType = [UIUserNotificationType.Alert,UIUserNotificationType.Badge,UIUserNotificationType.Sound] 
    let notificationSettings = UIUserNotificationSettings(forTypes: notificationTypes, categories: nil) 
    UIApplication.sharedApplication().registerForRemoteNotifications() 
    UIApplication.sharedApplication().registerUserNotificationSettings(notificationSettings)