作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我可以访问 didFinishLaunchingWithOptions 通过下面的实现。但是,我需要 界面窗口 多变的。我不知道如何得到它。我正在使用 Xcode 12 测试版。 iOS14,SwiftUI 生命周期。
import SwiftUI
@main
struct SSOKit_DemoApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
print("hello world!!!")
return true
}
}
最佳答案
从 iOS 13 开始,可以安全地假设获取对关键窗口的引用的正确方法是通过 UIWindowSceneDelegate
.
@main
struct DemoApp: App {
var window: UIWindow? {
guard let scene = UIApplication.shared.connectedScenes.first,
let windowSceneDelegate = scene.delegate as? UIWindowSceneDelegate,
let window = windowSceneDelegate.window else {
return nil
}
return window
}
[...]
}
关于ios - 如何在 iOS 14 @main 文件中获取 UIWindow 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62652555/
我是一名优秀的程序员,十分优秀!