diff --git a/suixinkan/AppDelegate.swift b/suixinkan/AppDelegate.swift index 87fa38c..1017f41 100644 --- a/suixinkan/AppDelegate.swift +++ b/suixinkan/AppDelegate.swift @@ -10,7 +10,8 @@ import UIKit @main class AppDelegate: UIResponder, UIApplicationDelegate { - + /// 兼容部分 Objective-C SDK 通过 UIApplicationDelegate.window 访问主窗口的场景。 + @objc var window: UIWindow? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { UmengBootstrap.configureIfNeeded() diff --git a/suixinkan/SceneDelegate.swift b/suixinkan/SceneDelegate.swift index 9c0ef58..1499d2d 100644 --- a/suixinkan/SceneDelegate.swift +++ b/suixinkan/SceneDelegate.swift @@ -22,12 +22,16 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { window.rootViewController = AppRouter.makeRootViewController() window.makeKeyAndVisible() self.window = window + (UIApplication.shared.delegate as? AppDelegate)?.window = window registerNotifications() } func sceneDidDisconnect(_ scene: UIScene) { NotificationCenter.default.removeObserver(self) + if (UIApplication.shared.delegate as? AppDelegate)?.window === window { + (UIApplication.shared.delegate as? AppDelegate)?.window = nil + } } private func registerNotifications() {