[英]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.