firebase 在AppDelegate中设置初始视图控制器时完全黑屏

im9ewurl  于 2023-08-07  发布在  其他
关注(0)|答案(3)|浏览(117)

如果user = nil,我想做的就是进入登录屏幕。否则,它会转到应用程序的main/home部分,该部分由Tab Bar Controller的第一个视图控制器组成
下面是我的app delegate:

import UIKit
import Firebase

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    FirebaseApp.configure()
    let storyboard = UIStoryboard(name: "Main", bundle: nil)

    if Auth.auth().currentUser == nil && !UserDefaults.standard.bool(forKey: "hasViewedWalkthrough") {

        let initialViewController = storyboard.instantiateViewController(withIdentifier: "WalkthroughViewController") as? WalkthroughViewController
        self.window?.rootViewController = initialViewController

    } else if Auth.auth().currentUser == nil && UserDefaults.standard.bool(forKey: "hasViewedWalkthrough") {

        let initialViewController = storyboard.instantiateViewController(withIdentifier: "loginViewController") as? LoginViewController
        self.window?.rootViewController = initialViewController

    } else {

        let initialViewController = storyboard.instantiateViewController(withIdentifier: "homeTabBarController") as? MainTabBarViewController
        self.window?.rootViewController = initialViewController

    }

    self.window?.makeKeyAndVisible()
    return true
}

字符串
我无法进入注册或登录屏幕。我总是被带到主屏幕上。我知道如果我在故事板中手动将它们设置为初始视图控制器,屏幕渲染效果会很好。
我尝试了很多方法,但没有一个有效。

更新x1c 0d1x

ifsvaxew

ifsvaxew1#

试试这个:

let storyBoard = UIStoryboard(name: "Main", bundle: nil)
        let initialViewController = storyBoard.instantiateViewControllerWithIdentifier("homeTabBarController") as? TabBarViewController // whatever your swift file is called 
        self.window?.rootViewController = storyBoard

字符串
对if语句的每个语句使用该代码,显然将视图控制器的名称分别更改为登录名。

q8l4jmvw

q8l4jmvw2#

对于将来阅读本文的人来说,iOS 13引入了SceneDelegate,现在所有与UI相关的东西都应该从那时起配置。我遇到了同样的问题,并通过使用此代码解决了它。现在应该从这里配置自定义窗口。

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
    // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
    // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
    guard let sceneWindow = (scene as? UIWindowScene) else { return }

    window = UIWindow(frame: sceneWindow.coordinateSpace.bounds)
    window?.windowScene = sceneWindow
    window?.makeKeyAndVisible()

    if let navigationController = Storyboard.Main.initialViewController as? UINavigationController,
       let viewController = navigationController.children.first as? CountriesViewController {
        viewController.inject(CountriesViewModel(provider: CountryAPI(),
                                                 informTo: viewController),
                                                 navigator: CountriesNavigator(navigationController: navigationController))

        window?.rootViewController = navigationController
    }
}

字符串

dy2hfwbg

dy2hfwbg3#

我不得不从头开始创建一个新项目,没有任何工作。这花了一些时间,但基本上我粘贴了我所有的文件和我所有的xibs了。对于故事板,我总是创建一个包含所有其他视图的视图。当我复制那个视图并把全零的约束放到超级视图中时,它就工作了。无缘无故的大量复制粘贴

相关问题