From 09809d08ef24100a0c0b131abcb879b9646b47aa Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Sat, 7 Feb 2026 18:21:46 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Handle=20unauthorised=20notificatio?= =?UTF-8?q?n=20state?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AccountNotificationInspectorView.swift | 86 +++++++++++++------ 1 file changed, 62 insertions(+), 24 deletions(-) diff --git a/iOS/Account/AccountNotificationInspectorView.swift b/iOS/Account/AccountNotificationInspectorView.swift index 134e8c7b4..8478ac711 100644 --- a/iOS/Account/AccountNotificationInspectorView.swift +++ b/iOS/Account/AccountNotificationInspectorView.swift @@ -14,42 +14,80 @@ struct AccountNotificationInspectorView: View { @Environment(\.dismiss) private var dismiss @State private var uuid = UUID() + @State private var authorisationStatus: UNAuthorizationStatus = .notDetermined var account: Account! var body: some View { NavigationStack { - List(account.flattenedFeeds().sorted(by: { a, b in - a.nameForDisplay < b.nameForDisplay - }), id: \.feedID) { feed in - Toggle(isOn: Binding(get: { feed.isNotifyAboutNewArticles ?? false }, set: { feed.isNotifyAboutNewArticles = $0 })) { - HStack { - if let img = IconImageCache.shared.imageFor(feed.sidebarItemID!) { - IconImageView(icon: img) - .id(uuid) - } else if let img = feed.smallIcon { - IconImageView(icon: img) - .id(uuid) + if authorisationStatus == .notDetermined || authorisationStatus == .denied { + VStack { + ContentUnavailableView("Notifications Disabled", + systemImage: "bell.slash", + description: Text("Enable Notifications in Settings", comment: "Enable Notifications in Settings")) + + Button { + UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!) + } label: { + Text("Open Settings", comment: "Open Settings") + } + .buttonStyle(.borderedProminent) + .tint(.accentColor) + } + .navigationTitle(Text("New Article Notifications", comment: "New Article Notifications")) + .navigationBarTitleDisplayMode(.inline) + .toolbar { + ToolbarItem(placement: .topBarTrailing) { + Button(role: .close) { + dismiss() } - Text(verbatim: feed.nameForDisplay) - Spacer() } } - .tint(.accentColor) - } - .navigationTitle(Text("New Article Notifications", comment: "New Article Notifications")) - .navigationBarTitleDisplayMode(.inline) - .toolbar { - ToolbarItem(placement: .topBarTrailing) { - Button(role: .close) { - dismiss() + } else { + List(account.flattenedFeeds().sorted(by: { a, b in + a.nameForDisplay < b.nameForDisplay + }), id: \.feedID) { feed in + Toggle(isOn: Binding(get: { feed.isNotifyAboutNewArticles ?? false }, set: { feed.isNotifyAboutNewArticles = $0 })) { + HStack { + if let img = IconImageCache.shared.imageFor(feed.sidebarItemID!) { + IconImageView(icon: img) + .id(uuid) + } else if let img = feed.smallIcon { + IconImageView(icon: img) + .id(uuid) + } + Text(verbatim: feed.nameForDisplay) + Spacer() + } + } + .tint(.accentColor) + } + .navigationTitle(Text("New Article Notifications", comment: "New Article Notifications")) + .navigationBarTitleDisplayMode(.inline) + .toolbar { + ToolbarItem(placement: .topBarTrailing) { + Button(role: .close) { + dismiss() + } } } + .onReceive(NotificationCenter.default.publisher(for: Notification.Name.feedIconDidBecomeAvailable)) { _ in + uuid = UUID() + } } - .onReceive(NotificationCenter.default.publisher(for: Notification.Name.feedIconDidBecomeAvailable)) { _ in - uuid = UUID() - } + + } + .task { + let settings = await UNUserNotificationCenter.current().notificationSettings() + self.authorisationStatus = settings.authorizationStatus + } + .onReceive(NotificationCenter.default.publisher(for: UIApplication.didBecomeActiveNotification), perform: { _ in + Task { + let settings = await UNUserNotificationCenter.current().notificationSettings() + self.authorisationStatus = settings.authorizationStatus + } + }) } }