【发布时间】:2019-08-17 03:00:53
【问题描述】:
在我的应用程序的载入流程中,我有一个页面询问用户是否要允许通知警报(通过UrbanAirship)。
在用户按下"Don't Allow" 或"Allow" 在随后的SDK 生成UIAlert 时,我想执行一些操作。在这种情况下,当用户按下两个警报按钮中的一个时,转换到入职流程的下一页。此外,在"Allow" 的情况下,更新本地存储中的变量以指示用户之前已授予推送通知权限。
理想情况下,我希望能够为每个按钮按下实现关闭/回调,但我无法从 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 + 论坛中找到的最接近解决方案的是this forum question from 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 对于 BOTH 允许和拒绝来自 SDK 呈现警报的结果是否可能?如果是这样,我该怎么做?
【问题讨论】:
-
iOS 会自动提示用户允许通知并说明您提供的原因。您是否有某些原因需要创建自己的警报?
-
我知道,我只是希望能够在显示的默认警报上执行完成块(即仅在按下
Allow或Don't Allow操作按钮之一时执行页面转换)。
标签: ios swift push-notification permissions urbanairship.com