简体   繁体   English

UrbanAirship iOS SDK-是否有通知权限请求回叫?

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

During my App's onboarding flow I have a page asking the user if they want to allow notification alerts (via UrbanAirship ). 在我的应用程序的入职流程中,我有一个页面询问用户是否要允许通知警报(通过UrbanAirship )。

On either the user pressing "Don't Allow" or "Allow" in the subsequent SDK generated UIAlert I would like to perform some actions. 在用户在随后的SDK生成的UIAlert按下"Don't Allow""Allow" ,我想执行一些操作。 In this case, transitioning to the next page of the onboarding flow when a user presses one of the two alert buttons. 在这种情况下,当用户按下两个警报按钮之一时,转换到入职流程的下一页。 Furthermore, in the "Allow" case, update a variable in local storage to indicate that the user has previously given permission for push notifications. 此外,在"Allow"情况下,更新本地存储中的变量以指示用户先前已授予推送通知权限。

Ideally I'd like to be able to implement a closure/callback for each of these button presses but I haven't been able to find out how to do this from the UrbanAirship docs. 理想情况下,我希望能够为这些按钮的每次按下实现关闭/回调,但是我还无法从UrbanAirship文档中找到如何执行此操作的UrbanAirship

Currently I have the following: 目前,我有以下内容:

@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)
}

But this has the problem of instantiating the page transition and then presenting the notifications alert on top of the next page in the onboarding flow. 但这存在实例化页面过渡, 然后在入职流程中的下一页顶部显示通知警报的问题。

The closest thing to a solution that I've found in the UrbanAirship docs + forums is this forum question from 2017 , but this only seems to give a possible "closure" solution for the "allow" button-pressed case (via didRegisterForRemoteNotifications ), whereas I still want to be able to progress my users through onboarding even if they deny notifications permissions. 我在UrbanAirship docs +论坛中找到的最接近解决方案的问题是2017年的论坛问题 ,但这似乎只能为"allow"按钮按下的情况(通过didRegisterForRemoteNotifications )提供可能的“关闭”解决方案,尽管我的用户拒绝了通知权限,但我仍然希望能够继续通过他们的入职。

Ideally, I'd like to be able to implement completion closures similar to what is possible with a standard UIAlertController , for example: 理想情况下,我希望能够实现类似于标准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)
}

My question is, therefore, is this possible with UrbanAirship for BOTH the permission granted and rejected outcomes from the SDK presented alert? 因此,我的问题是, UrbanAirship for BOTH是否有可能同时获得SDK发出的警报的允许和拒绝结果警报? If so, how do I do it? 如果是这样,我该怎么办?

You can use enableUserPushNotifications : 您可以使用enableUserPushNotifications

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

That will cause the system prompt for the permission and give you the result true if notifications are enabled, otherwise false . 这将导致权限系统提示,给你的结果true ,如果启用通知,否则false

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用UrbanAirship iOS SDK的推送通知的自定义方法 - Custom methods for push notifications using UrbanAirship iOS SDK Unity3D推送通知iOS和Android Vuforia和UrbanAirship - Unity3D Push Notifications iOS & Android Vuforia & UrbanAirship 如何控制Netmera ios sdk何时提示“推送通知”权限? - How to control when Netmera ios sdk will prompt Push notifications permission? Facebook IOS SDK:将Facebook请求回调数据存储到全局变量中 - Facebook IOS SDK: store facebook request callback data into global variable Facebook iOS SDK强制嵌入式Webview请求发布流权限 - Facebook iOS SDK Force Embedded Webview to request publish stream permission iOS 9不要求远程通知权限 - IOS 9 not asking permission for remote notifications IOS上带有URL的UrbanAirship Push - UrbanAirship Push with URL on IOS 要求iOS 8中的远程通知权限 - Ask for Permission for Remote Notifications in iOS 8 存档时Xcode 7中的UrbanAirship iOS SDK错误:libUAirship-6.2.0.a(UAWalletAction.o)'不包含bitcode - UrbanAirship iOS SDK error in Xcode 7 when archiving: libUAirship-6.2.0.a (UAWalletAction.o)' does not contain bitcode iOS 9通知 - 当我请求权限时,为什么我的应用名称丢失了? - iOS 9 Notifications - why is my app name missing when I request permission?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM