I’d like to create a versatile “Push Notifications” toggle to my SettingsView.
By versatile, I mean I’d like for the toggle to be automatically set to enabled if the app’s notification current permission is authorized, provisional, or ephemeral. And disabled if denied or not determined.
Ideally, the toggle would also request permission if set to “not determined.” And send to App Settings if set to “denied.”
Snippet of my SettingsView
struct SettingsView: View {
let notify = NotificationHandler()
@State private var enablePushNotifications = false
var body: some View {
NavigationView {
Form {
Section(header: Text("Notifications")) {
let toggle = Binding<Bool> (
get: { self.enablePushNotifications }
set: { newValue in
self.enablePushNotifications = newValue
})
Toggle("Push Notifications", isOn: toggle)
}
}
}
}
Moe A is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.