SPB Git

Repository Public

NotificationSettings.swift 1.6 KB 30 lines swift

1// SP Wallet iOS2// File: Features/Settings/NotificationSettings.swift3// Description: Local notification permission and switch. Notifications are only ever posted for events the server confirmed.4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7import SwiftUI8import UserNotifications910struct NotificationSettingsRows: View {11    @Environment(Preferences.self) private var prefs12    @State private var status: UNAuthorizationStatus = .notDetermined13    var body: some View {14        @Bindable var prefs = prefs15        Toggle(String(localized: "Notifier les événements confirmés"), isOn: Binding(get: { prefs.notifications && status == .authorized }, set: { on in16            if on {17                Task {18                    let ok = (try? await UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge])) ?? false19                    status = await UNUserNotificationCenter.current().notificationSettings().authorizationStatus20                    prefs.notifications = ok21                }22            } else { prefs.notifications = false }23        }))24        if status == .denied { Text(String(localized: "Les notifications sont refusées pour SP Wallet dans Réglages.")).font(.spFootnote).foregroundStyle(Theme.warn) }25        Text(String(localized: "Transaction confirmée ou échouée, ordre exécuté, limite de risque atteinte, agent arrêté, état du signataire. Le contenu ne montre aucun montant sur l’écran verrouillé."))26            .font(.spFootnote).foregroundStyle(Theme.mute)27            .task { status = await UNUserNotificationCenter.current().notificationSettings().authorizationStatus }28    }29}30
Files main
Menu

Theme