Tusker/Tusker/Screens/Preferences/Notifications/NotificationsPrefsView.swift

62 lines
1.9 KiB
Swift

//
// NotificationsPrefsView.swift
// Tusker
//
// Created by Shadowfacts on 4/6/24.
// Copyright © 2024 Shadowfacts. All rights reserved.
//
import SwiftUI
import UserNotifications
import UserAccounts
import PushNotifications
import TuskerComponents
struct NotificationsPrefsView: View {
@State private var error: NotificationsSetupError?
@ObservedObject private var userAccounts = UserAccountsManager.shared
var body: some View {
List {
Section {
ForEach(userAccounts.accounts) { account in
PushInstanceSettingsView(account: account)
}
}
.appGroupedListRowBackground()
if #available(iOS 15.4, *) {
Section {
Button {
let str = if #available(iOS 16.0, *) {
UIApplication.openNotificationSettingsURLString
} else {
UIApplicationOpenNotificationSettingsURLString
}
if let url = URL(string: str) {
UIApplication.shared.open(url)
}
} label: {
Text("Open Notification Settings…")
}
}
.appGroupedListRowBackground()
}
}
.listStyle(.insetGrouped)
.appGroupedListBackground(container: PreferencesNavigationController.self)
.navigationTitle("Notifications")
}
}
private enum NotificationsSetupError: LocalizedError {
case requestingAuthorization(any Error)
var errorDescription: String? {
switch self {
case .requestingAuthorization(let error):
"Notifications authorization request failed: \(error.localizedDescription)"
}
}
}