ios - 是否可以在应用程序中提供设置以让用户打开或关闭 Braze 通知?
问题描述
我正在使用 Braze 将通知推送到我们的应用程序。是否可以在我的应用程序中添加设置以打开或关闭推送通知?如果是,该怎么做?
解决方案
您无法在应用中添加通知设置。但您可以检查通知权限状态。通过使用此代码
let current = UNUserNotificationCenter.current()
current.getNotificationSettings(completionHandler: { (settings) in
if settings.authorizationStatus == .notDetermined {
// Notification permission has not been asked yet, go for it!
}
if settings.authorizationStatus == .denied {
// Notification permission was previously denied, go to settings & privacy to re-enable
}
if settings.authorizationStatus == .authorized {
// Notification permission was already granted
}
})
如果身份验证状态被拒绝或未确定,那么您可以使用任何控件(按钮、开关)将用户重定向到您的应用程序设置以打开通知。使用此代码:
guard let settingsUrl = URL(string: UIApplicationOpenSettingsURLString) else {
return
}
if UIApplication.shared.canOpenURL(settingsUrl) {
UIApplication.shared.open(settingsUrl, completionHandler: { (success)
in
print("Settings opened: \(success)
") // Prints true
})
}
推荐阅读
- c++ - 使用函数返回多个值
- javascript - 在 browser.runtime.getBackgroundPage() 中访问变量
- python - 如何从 matplotlib 中的循环中绘制超参数?
- python - 从没有重复的句子中打印出元音
- javascript - 如何将具有嵌套对象复合体的数组对象转换为 CSV 文件
- excel - 我的公式改变了表格本身的方程式有什么原因吗?
- node.js - 将 firebase 存储与 Admin sdk node.js 一起使用
- c# - C#-UWP FolderPicker 在 Windows 10 的 FolderOpenDialog 上挂起
- c++ - Folly 项目的 Cmake 文件
- java - java 矩形:为什么错误“getPreferredSize()”