【问题标题】:IOS Parse Homescreen when currentUser() != nilIOS Parse Homescreen when currentUser() != nil
【发布时间】:2020-09-27 18:37:30
【问题描述】:

我正在为此苦苦挣扎(看起来很简单),但我认为这可能是因为我的登录/注册 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】:

    您需要在 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()
        }
    
    }
    

    【讨论】:

    • 嘿,还有一件事。现在我的应用程序启动到黑屏,我尝试调试它并阅读了许多答案。我不确定问题是什么,我可能需要在 info.plist 中添加一些内容吗?当我从 SceneDelegate 中注释掉代码时,应用程序会显示登录屏幕并且工作正常,否则我只会在启动屏幕后被发送到黑屏。不确定发生了什么变化。 (我确实更新了我的苹果开发者帐户,但认为这并不重要)
    • 我已经编辑了我的答案。如果您以编程方式设置 rootViewController,则只想为窗口分配一个值。所以,简而言之,我将 window = UIWindow(windowScene: windowScene) 语句移到了 if 块中。
    • 谢谢先生。明白了,除非以编程方式实例化 rootviewcontroller,否则不要给 window 赋值。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多