From cf0d2143c225336984a6bc8fa7ef814a18b02bd1 Mon Sep 17 00:00:00 2001 From: Rishat Shamsutdinov Date: Tue, 7 Dec 2021 00:13:50 +0500 Subject: [PATCH] feat(splash-screen): Make splash work in apps that use scenes (#631) Co-authored-by: jcesarmobile --- splash-screen/ios/Plugin/SplashScreen.swift | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/splash-screen/ios/Plugin/SplashScreen.swift b/splash-screen/ios/Plugin/SplashScreen.swift index a94864c48..10509add0 100644 --- a/splash-screen/ios/Plugin/SplashScreen.swift +++ b/splash-screen/ios/Plugin/SplashScreen.swift @@ -117,16 +117,17 @@ import Capacitor // Update the bounds for the splash image. This will also be called when // the parent view observers fire private func updateSplashImageBounds() { - guard let delegate = UIApplication.shared.delegate else { - CAPLog.print("Unable to find root window object for SplashScreen bounds. Please file an issue") - return + var window: UIWindow? = UIApplication.shared.delegate?.window as? UIWindow + + if #available(iOS 13, *), window == nil { + window = (UIApplication.shared.connectedScenes.first as? UIWindowScene)?.windows.filter({$0.isKeyWindow}).first } - guard let window = delegate.window as? UIWindow else { + if let unwrappedWindow = window { + viewController.view.frame = CGRect(origin: CGPoint(x: 0, y: 0), size: unwrappedWindow.bounds.size) + } else { CAPLog.print("Unable to find root window object for SplashScreen bounds. Please file an issue") - return } - viewController.view.frame = CGRect(origin: CGPoint(x: 0, y: 0), size: window.bounds.size) } override public func observeValue(forKeyPath keyPath: String?, of object: Any?, change _: [NSKeyValueChangeKey: Any]?, context: UnsafeMutableRawPointer?) {