Загрузка данных


import UIKit

class SceneDelegate: UIResponder, UIWindowSceneDelegate {

    var window: UIWindow?

    func scene(
        _ scene: UIScene,
        willConnectTo session: UISceneSession,
        options connectionOptions: UIScene.ConnectionOptions
    ) {

        guard let windowScene = scene as? UIWindowScene else {
            return
        }

        let window = UIWindow(windowScene: windowScene)
        self.window = window

        // If AppCoordinator creates the root controller itself,
        // just make the window visible.
        window.makeKeyAndVisible()

        // Launch app flow
        AppCoordinator.shared.startLaunch()
    }

    func sceneDidBecomeActive(_ scene: UIScene) {
        guard let app = UIApplication.shared.delegate as? AppDelegate else { return }
        AppDelegateManager.shared.applicationDidBecomeActive(UIApplication.shared)
    }

    func sceneWillResignActive(_ scene: UIScene) {
        AppDelegateManager.shared.applicationWillResignActive(UIApplication.shared)
    }

    func sceneWillEnterForeground(_ scene: UIScene) {

        guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else {
            return
        }

        appDelegate.startDynatrace()

        Task {
            _ = try await AppCoordinator.shared.updateStateBeforeApplicationBecomeActive()

            await MainActor.run {
                AppDelegateManager.shared.applicationWillEnterForeground(
                    UIApplication.shared
                )
            }
        }
    }

    func sceneDidEnterBackground(_ scene: UIScene) {

        Task {
            try? await CoreDataKit.CoreDataManager.shared.saveAllContexts()
        }

        guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else {
            return
        }

        appDelegate.cleanLoggedSystemWidgetSizes()
        WidgetCenter.shared.reloadAllTimelines()
        appDelegate.updateAppBadge(UIApplication.shared)

        AppDelegateManager.shared.applicationDidEnterBackground(
            UIApplication.shared
        )

        Dynatrace.endVisit()
        Dynatrace.shutdown()
    }
}