Created
May 17, 2020 21:19
-
-
Save SerggioC/421aea80b8b092bdbcb5a145d6d566fd to your computer and use it in GitHub Desktop.
Access the window object from SceneDelegate or AppDelegate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func getCurrentWindow() -> UIWindow? { | |
if #available(iOS 13.0, *) { | |
if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene, | |
let sceneDelegate = windowScene.delegate as? SceneDelegate { | |
return sceneDelegate.window | |
} else { | |
return nil | |
} | |
} else { | |
// Fallback on earlier versions | |
return self.window | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment