iOS、swift 上未调用 sceneDidEnterBackground

sceneDidEnterBackground is not called on iOS, swift

我正在使用协调器模式实现 iOS 应用程序,我需要在应用程序进入后台时显示一些隐私屏幕。

class SceneDelegate: UIResponder, UIWindowSceneDelegate {

    var window: UIWindow?
    var coordinator: MainCoordinator?


    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        guard let scene = scene as? UIWindowScene else { return }
    
        if let registry = DependencyResolver.shared as? DependencyRegistry {
            DependencyGraph.setup(for: registry)
        }
    
        let navController = UINavigationController()
        navController.setNavigationBarHidden(true, animated: false)
        coordinator = MainCoordinator(navigationController: navController)
        coordinator?.start()
        self.window = UIWindow.init(windowScene: scene)
        window?.rootViewController = navController
        window?.makeKeyAndVisible()
    }

    func sceneWillEnterForeground(_ scene: UIScene) {
        hidePrivacyProtectionWindow()
    }

    func sceneDidEnterBackground(_ scene: UIScene) {
        showPrivacyProtectionWindow()
    }

    ...

    // MARK: Privacy Protection
    private var privacyProtectionWindow: UIWindow?

    private func showPrivacyProtectionWindow() {
        guard let windowScene = self.window?.windowScene else {
            return
        }

        privacyProtectionWindow = UIWindow(windowScene: windowScene)
        let storyboard = UIStoryboard(name: "LaunchScreen", bundle: nil)
        let vc = storyboard.instantiateViewController(withIdentifier: "splash")
        privacyProtectionWindow?.rootViewController = vc
        privacyProtectionWindow?.windowLevel = .alert + 1
        privacyProtectionWindow?.makeKeyAndVisible()
    }

    private func hidePrivacyProtectionWindow() {
        privacyProtectionWindow?.isHidden = true
        privacyProtectionWindow = nil
    }
}

进入时,sceneWillEnterForeground() 被调用。在进入后台时, sceneDidEnterBackground() 不会被调用。我错过了什么?

发题10分钟后自己找的,一开始用的方法不对。这将适用于我想要实现的目标:

func sceneDidBecomeActive(_ scene: UIScene) {
    hidePrivacyProtectionWindow()
}

func sceneWillResignActive(_ scene: UIScene) {
    showPrivacyProtectionWindow()
}