[currentUser()时,IOS解析主屏幕!=无

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

我为此感到吃力(似乎很简单),但是我认为这可能是因为我的登录/注册VC位于导航控制器中,而我的其他应用程序(主屏幕等)位于单独的TabBarController中。

我的“是初始VC”设置为保存我的注册和登录VC的导航控制器,它可以启动并正常运行,我能够登录并像这样进入HomeVC:

func transitionToHome() {
    let homeViewController = storyboard?.instantiateViewController(identifier: Constants.Storyboard.homeViewController)
    view.window?.rootViewController = homeViewController
    view.window?.makeKeyAndVisible()
}

在我的AppDelegate中,我有以下代码:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    setupParse()

    if  PFUser.current() != nil {
        let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
        let homeVC = storyboard.instantiateViewController(identifier: Constants.Storyboard.homeViewController)
        self.window?.makeKeyAndVisible()
        self.window?.rootViewController?.present(homeVC, animated: true, completion: nil)
    }

    return true
}

我也尝试过向后尝试(Home TabbarVC是Initial,并且在应用程序委托中,如果Pf.current()== nil,请使用登录启动),并确保PFUser.current()在注销后设置为nil,然后是的,但是它仍然对我不起作用。我已经阅读了其他类似的问题,但我认为我的问题可能是标签栏和导航-或使用Windows的东西。谢谢你。

ios swift parsing parse-platform
1个回答
1
投票

您需要将代码移动到SceneDelegate内,并且需要对其进行一些更改:

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 windowScene = (scene as? UIWindowScene) else { return }

    if  PFUser.current() != nil {
        window = UIWindow(windowScene: windowScene)
        let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
        let homeVC = storyboard.instantiateViewController(identifier: Constants.Storyboard.homeViewController)
        window?.rootViewController = homeVC
        self.window?.makeKeyAndVisible()
    }

}
© www.soinside.com 2019 - 2024. All rights reserved.