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