如果Firebase获得登录用户,我想将根VC设置为Home-VC。控制台说找到了该用户,但是VC并未更改。
这是我的代码:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
//FirebaseConfigure
FirebaseApp.configure()
Auth.auth().addStateDidChangeListener { auth,user in
let storyboard = UIStoryboard(name: "Main", bundle: nil)
if user != nil {
print("User found")
UserService.observeUserProfile(user!.uid) { userProfile in
UserService.currentUserProfile = userProfile
}
let controller = storyboard.instantiateViewController(withIdentifier: "Home")
self.window?.rootViewController = controller
self.window?.makeKeyAndVisible()
}else{
print("User not found")
UserService.currentUserProfile = nil
let controller = storyboard.instantiateViewController(withIdentifier: "Out")
self.window?.rootViewController = controller
self.window?.makeKeyAndVisible()
}
}
return true
}
这里是我的分镜脚本:
要以编程方式覆盖rootViewController
,您需要首先禁用默认为Main.storyboard
文件的应用主界面。这是您的操作方法:
info.plist
文件中删除这些行(作为源代码打开。)><key>UIMainStoryboardFile</key>
<string>Main</string>
UISceneDelegate
,请同时删除该项目:<key>UISceneStoryboardFile</key>
<string>Main</string>