In iOS 13+ the window will be nil from didFinishLaunchingWithOptions
in the app delegate. Instead move your code to willConnectTo session
method in SceneDelegate
:
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
if let tabBarController = window?.rootViewController as? UITabBarController {
print("rootVC")
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "NavController")
vc.tabBarItem = UITabBarItem(tabBarSystemItem: .topRated, tag: 1)
tabBarController.viewControllers?.append(vc)
}
guard let _ = (scene as? UIWindowScene) else { return }
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…