WindowSceneReader
📱 Access UIWindowScene in SwiftUI
Install / Use
/learn @divadretlaw/WindowSceneReaderREADME
WindowSceneReader
Access the current UIWindowScene and UIWindow from any SwiftUI view.
Usage
SwiftUI Lifecycle
Read the current UIWindowScene with WindowSceneReader
@main
struct MyApp: App {
var body: some Scene {
WindowGroup {
WindowSceneReader { windowScene in
ContentView()
}
}
}
}
alternatively, just add windowScene() if you only need the window scene on child views.
@main
struct MyApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.windowScene()
}
}
}
On child views the UIWindowScene will be available in the Environment
UIKit Lifecycle
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
if let windowScene = scene as? UIWindowScene {
let rootView = ContentView()
.windowScene(windowScene)
let window = UIWindow(windowScene: windowScene)
window.rootViewController = UIHostingController(rootView: rootView)
self.window = window
window.makeKeyAndVisible()
}
}
Environment
@Environment(\.windowScene) var windowScene
The @Environment(\.windowScene) var windowScene defaults to the first connected UIWindowScene or nil if no UIWindowScene is connected.
License
See LICENSE
Related Skills
node-connect
343.3kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
92.1kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
343.3kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
343.3kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
