簡體   English   中英

UrbanAirship iOS SDK-是否有通知權限請求回叫?

[英]UrbanAirship iOS SDK - Is There A Notifications Permission Request Callback?

在我的應用程序的入職流程中,我有一個頁面詢問用戶是否要允許通知警報(通過UrbanAirship )。

在用戶在隨后的SDK生成的UIAlert按下"Don't Allow""Allow" ,我想執行一些操作。 在這種情況下,當用戶按下兩個警報按鈕之一時,轉換到入職流程的下一頁。 此外,在"Allow"情況下,更新本地存儲中的變量以指示用戶先前已授予推送通知權限。

理想情況下,我希望能夠為這些按鈕的每次按下實現關閉/回調,但是我還無法從UrbanAirship文檔中找到如何執行此操作的UrbanAirship

目前,我有以下內容:

@IBAction func permissionsButtonPressed(_ sender: Any) {
        UAirship.push().userPushNotificationsEnabled = true
        UAirship.push().defaultPresentationOptions = [.alert, .badge, .sound]
        UAirship.push().resetBadge()
        UAirship.push().isAutobadgeEnabled = true

        //Update a variable in local storage
        // ...

        performSegue(withIdentifier: "exampleIdentifier", sender: self)
}

但這存在實例化頁面過渡, 然后在入職流程中的下一頁頂部顯示通知警報的問題。

我在UrbanAirship docs +論壇中找到的最接近解決方案的問題是2017年的論壇問題 ,但這似乎只能為"allow"按鈕按下的情況(通過didRegisterForRemoteNotifications )提供可能的“關閉”解決方案,盡管我的用戶拒絕了通知權限,但我仍然希望能夠繼續通過他們的入職。

理想情況下,我希望能夠實現類似於標准UIAlertController可能的完成關閉,例如:

func setupPermissionsAlert() {
    let alert = UIAlertController(title: "This App Would Like to Send You Notifications", message: "An Interesting and Informative Message", preferredStyle: UIAlertController.Style.alert)
    alert.addAction(UIAlertAction(title: "Don't Allow", style: UIAlertAction.Style.default, handler: { [unowned self] action in
        //Some action
        self.notAllowedCompletion()
    }))
    alert.addAction(UIAlertAction(title: "Allow", style: UIAlertAction.Style.default, handler: { [unowned self] action in
        //Another action
       self.allowedCompletion()
    }))

    //N.B. topMostViewController() is a custom method to locate the topMostViewController presented
    UIApplication.shared.topMostViewController()?.present(alert, animated: true, completion: nil)
}

因此,我的問題是, UrbanAirship for BOTH是否有可能同時獲得SDK發出的警報的允許和拒絕結果警報? 如果是這樣,我該怎么辦?

您可以使用enableUserPushNotifications

UAirship.push().enableUserPushNotifications({ (result) in
  // handle result
})

這將導致權限系統提示,給你的結果true ,如果啟用通知,否則false

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM