0

我正在使用 Xcode 11 和 Swift 5.0。我从另一个使用 Swift 4.2 的应用程序中复制了我的代码。该代码在 AppDelegate 中实例化一个 tabBarViewController,将窗口更改为 tabBarVC,并在满足某些条件时显示它。但它不适用于 Swift 5.0 和 Xcode 11。这是代码:

var window: UIWindow?

func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
    // Run Firebase
    FirebaseApp.configure()
    // Check Firebase Auth to see if the user is signed in already.
    if Auth.auth().currentUser != nil {
        print ("User is already authenticated and signed in.")
        // Check to make sure the user is stored in local settings.
        if let appUser = LocalStorageService.loadCurrentUser() {
            print ("Local storage has a user: \(appUser)")
            // Create a tab bar controller.
            let tabBarVC = UIStoryboard(name: "Main", bundle: .main).instantiateViewController(withIdentifier: Constants.Storyboard.tabBarController)
            // Show it
            window?.rootViewController = tabBarVC
            window?.makeKeyAndVisible()
        }
        return true // If auth has a user and there is local user, window changes.
    } else {
        print ("No Authenticated current user, must proceed with Login.")
        return false
    }
}

tabBarVC 已成功填充,但窗口仍然为零。然后应用程序显示不同的视图控制器。代码与我可以看到的原始应用程序没有什么不同。而那个仍然有效。想法将不胜感激。

4

1 回答 1

0

SceneDelegate从导航器中删除了 ,并从info.plist处理场景中删除了以下部分,现在它按预期工作(其他应用程序没有SceneDelegate或这些部分info.plist。我假设它们是在 Xcode 11 中创建项目时添加的):

在此处输入图像描述

我在 Apple 文档中了解了 iOS 13 的场景。我不打算使用场景,但如果有人确实想使用场景,他们将必须确定如何配置info.plist以允许在 AppDelegate 中实例化 VC。

于 2019-10-12T01:35:39.067 回答