繁体   English   中英

是否可以在应用程序中提供设置以让用户打开或关闭Braze通知?

[英]Is it possible to provide setting in app to let user turn on or off Braze notification?

我正在使用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
            })
        }

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM