Swift Firebase自动登录未显示其他ViewController

问题描述 投票:0回答:1

如果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
}

这里是我的分镜脚本:

Storyboard Home-VC IdentityInsp

Storyboard Home-VC AttributeInsp.

ios swift firebase storyboard viewcontroller
1个回答
0
投票

要以编程方式覆盖rootViewController,您需要首先禁用默认为Main.storyboard文件的应用主界面。这是您的操作方法:

  1. info.plist文件中删除这些行(作为源代码打开。)>
  2. <key>UIMainStoryboardFile</key>
    <string>Main</string>
    
  1. 如果您的项目使用的是UISceneDelegate,请同时删除该项目:
  2. <key>UISceneStoryboardFile</key>
    <string>Main</string>
    
© www.soinside.com 2019 - 2024. All rights reserved.