diff --git a/iOS/AppDelegate.swift b/iOS/AppDelegate.swift index e4e60658f..5fdfbdc74 100644 --- a/iOS/AppDelegate.swift +++ b/iOS/AppDelegate.swift @@ -208,11 +208,8 @@ final class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationC // MARK: - API func manualRefresh(errorHandler: @escaping ErrorHandlerBlock) { - assert(Thread.isMainThread) - UIApplication.shared.connectedScenes.compactMap( { $0.delegate as? SceneDelegate }).forEach { - $0.cleanUp(conditional: true) - } + sceneCoordinator?.cleanUp(conditional: true) AccountManager.shared.refreshAll(errorHandler: errorHandler) } @@ -244,7 +241,7 @@ final class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationC completionHandler([.list, .banner, .badge, .sound]) } - func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { + func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { defer { completionHandler() } let userInfo = response.notification.request.content.userInfo @@ -255,16 +252,12 @@ final class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationC case "MARK_AS_STARRED": handleMarkAsStarred(userInfo: userInfo) default: - if let sceneDelegate = response.targetScene?.delegate as? SceneDelegate { - sceneDelegate.handle(response) - DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: { - sceneDelegate.coordinator.dismissIfLaunchingFromExternalAction() - }) + handle(response) + DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { + self.sceneCoordinator?.dismissIfLaunchingFromExternalAction() } } - - } - + } } // MARK: - App Initialization @@ -395,15 +388,9 @@ private extension AppDelegate { ArticleThemeDownloader.shared.cleanUp() CoalescingQueue.standard.performCallsImmediately() - for scene in UIApplication.shared.connectedScenes { - if let sceneDelegate = scene.delegate as? SceneDelegate { - sceneDelegate.suspend() - } - } - + sceneCoordinator?.suspend() logger.info("Application processing suspended.") } - } // MARK: Background Tasks @@ -523,4 +510,9 @@ private extension AppDelegate { } }) } + + func handle(_ response: UNNotificationResponse) { + AccountManager.shared.resumeAllIfSuspended() + sceneCoordinator?.handle(response) + } } diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index 5a68e55a4..5b174b690 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -544,6 +544,7 @@ final class SceneCoordinator: NSObject, UndoableCommandRunner { fetchRequestQueue.cancelAllRequests() } + // TODO: find out what `conditional` means in this context. func cleanUp(conditional: Bool) { if isReadFeedsFiltered { rebuildBackingStores()