我正在尝试在 SceneDelegate 中设置我的入职屏幕。
当我运行下面的代码时,它会编译,但只是进入黑屏。
它们是 AppDelegate 的许多很棒的入门教程,但对于 iOS13 的新 SceneDelegate 来说却很少。我学习了本教程并尝试将其应用于 SceneDelegate,但我无法让它工作:https ://www.youtube.com/watch?v=y6t1woVd6RQ&t=537s
这是我的场景委托代码。
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
let launchedBefore = UserDefaults.standard.bool(forKey: "hasLaunched")
self.window = UIWindow(frame: UIScreen.main.bounds)
let launchStoryboard = UIStoryboard(name: "Onboarding", bundle: nil)
let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
var vc: UIViewController
if launchedBefore
{
vc = mainStoryboard.instantiateInitialViewController()!
}
else
{
vc = launchStoryboard.instantiateViewController(identifier: "Onboarding")
}
UserDefaults.standard.set(true, forKey: "hasLaunched")
self.window?.rootViewController = vc
self.window?.makeKeyAndVisible()
// guard let _ = (scene as? UIWindowScene) else { return }
}
我已经尝试过注释掉最后一个警卫声明和不注释掉它。