修复 AppDelegate window 兼容性
This commit is contained in:
@ -10,7 +10,8 @@ import UIKit
|
|||||||
@main
|
@main
|
||||||
class AppDelegate: UIResponder, UIApplicationDelegate {
|
class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||||
|
|
||||||
|
/// 兼容部分 Objective-C SDK 通过 UIApplicationDelegate.window 访问主窗口的场景。
|
||||||
|
@objc var window: UIWindow?
|
||||||
|
|
||||||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
||||||
UmengBootstrap.configureIfNeeded()
|
UmengBootstrap.configureIfNeeded()
|
||||||
|
|||||||
@ -22,12 +22,16 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
|
|||||||
window.rootViewController = AppRouter.makeRootViewController()
|
window.rootViewController = AppRouter.makeRootViewController()
|
||||||
window.makeKeyAndVisible()
|
window.makeKeyAndVisible()
|
||||||
self.window = window
|
self.window = window
|
||||||
|
(UIApplication.shared.delegate as? AppDelegate)?.window = window
|
||||||
|
|
||||||
registerNotifications()
|
registerNotifications()
|
||||||
}
|
}
|
||||||
|
|
||||||
func sceneDidDisconnect(_ scene: UIScene) {
|
func sceneDidDisconnect(_ scene: UIScene) {
|
||||||
NotificationCenter.default.removeObserver(self)
|
NotificationCenter.default.removeObserver(self)
|
||||||
|
if (UIApplication.shared.delegate as? AppDelegate)?.window === window {
|
||||||
|
(UIApplication.shared.delegate as? AppDelegate)?.window = nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func registerNotifications() {
|
private func registerNotifications() {
|
||||||
|
|||||||
Reference in New Issue
Block a user