I'm working on using Braze to push notification to our app. Is it possible to add a setting in my app to turn on or off push notification? If yes, how to do that?
you can't add notification settings in your app . but you can check notification permission status . by using this code
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
}
})
if auth status is denied or undetermined then you can redirect user to your application settings to on notification by using any control (button , switch) . using this code :
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
})
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.