From 23eb0cb0791ca48b1e6cf72cd539976b7b0b2349 Mon Sep 17 00:00:00 2001 From: Stuart Breckenridge Date: Thu, 23 Mar 2023 21:17:20 +0800 Subject: [PATCH] Monitor scenePhase instead of didEnterForeground --- iOS/Settings/General/SettingsView.swift | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/iOS/Settings/General/SettingsView.swift b/iOS/Settings/General/SettingsView.swift index 4609fa27e..c196a9d2d 100644 --- a/iOS/Settings/General/SettingsView.swift +++ b/iOS/Settings/General/SettingsView.swift @@ -14,6 +14,7 @@ import UserNotifications struct SettingsView: View { @Environment(\.dismiss) var dismiss + @Environment(\.scenePhase) var scenePhase @StateObject private var appDefaults = AppDefaults.shared @StateObject private var viewModel = SettingsViewModel() @@ -104,13 +105,13 @@ struct SettingsView: View { Task { await MainActor.run { self.viewModel.notificationPermissions = settings.authorizationStatus }} } } - .task { - for await _ in NotificationCenter.default.notifications(named: UIScene.willEnterForegroundNotification) { + .onChange(of: scenePhase, perform: { phase in + if phase == .active { UNUserNotificationCenter.current().getNotificationSettings { settings in Task { await MainActor.run { self.viewModel.notificationPermissions = settings.authorizationStatus }} } } - } + }) .dismissOnExternalContextLaunch() .fileImporter(isPresented: $viewModel.showImportView, allowedContentTypes: OPMLDocument.readableContentTypes) { result in switch result {