如何在 Scene Delegate 中的自动登录完成之前一直停留在启动屏幕上?

Posted

技术标签:

【中文标题】如何在 Scene Delegate 中的自动登录完成之前一直停留在启动屏幕上?【英文标题】:How to stay on the launch screen until auto-login in Scene Delegate is complete? 【发布时间】:2020-08-03 21:28:45 【问题描述】:

我试图在我的场景委托中自动登录后切换屏幕,一切正常,除了我的启动屏幕出现 10 毫秒,然后它转到我的 ViewController(初始视图控制器),然后将屏幕切换到我想要的屏幕它切换到。我的目标是在我登录场景委托时始终显示启动屏幕,然后在登录完成后切换屏幕。这是我正在使用的代码

var window: UIWindow?


    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).


        if let windowScene = scene as? UIWindowScene 
                  let window = UIWindow(windowScene: windowScene)
                  let storyboard = UIStoryboard(name: "Main", bundle: nil)
                  if KeychainWrapper.standard.string(forKey: "email") != nil && KeychainWrapper.standard.string(forKey: "password") != nil 
                        Auth.auth().signIn(withEmail: KeychainWrapper.standard.string(forKey: "email")!, password:  KeychainWrapper.standard.string(forKey: "password")!)  (result, error) in
                               if error == nil 
                                    if Auth.auth().currentUser!.isEmailVerified 
                                       /*getting data*/
                                         window.rootViewController = storyboard.instantiateViewController(identifier: "ViewingScreenController") 
                                          self.window = window
                                          window.makeKeyAndVisible()
                                     
                                     
                           
                                              
                        
                                         
                     
               
    

        
      // guard let _ = (scene as? UIWindowScene) else  return 
    ```

【问题讨论】:

“启动屏幕”是什么意思?您的意思是字面上的 LaunchScreen.storyboard 吗?如果是这样,你就误解了那是什么。 @matt 是的,我的意思是 LaunchScreen.storyboard。它不执行该功能吗? 您可以呈现一些特定的视图,直到自动记录完成。它可以看起来与启动屏幕相同。但是在加载您的应用程序之前会显示启动屏幕。不是之后。 @pawello2222 我也是这么想的,但最好的解决方案就是我想知道的 【参考方案1】:

您误解了启动屏幕是什么。它只是运行时您的应用启动之前呈现的过渡性事物。在许多情况下,它根本不可见!这很好,因为这意味着应用程序可以快速启动。在https://***.com/a/59700102/341994 上查看我的回答。

因此,您不应围绕启动屏幕构建任何功能;它不起作用。您的目标应该是通过启动屏幕,这意味着您的应用可以快速启动,这是正确的。那么你呈现什么取决于你;您的代码现在正在运行。

【讨论】:

以上是关于如何在 Scene Delegate 中的自动登录完成之前一直停留在启动屏幕上?的主要内容,如果未能解决你的问题,请参考以下文章

Swift Scene Delegate 在首次启动时不运行代码

Google Sign In 调用 App Delegate 中的方法后关闭 View Controller (iOS / Swift)

在 App Delegate 上调用服务器后如何更改根控制器?

如何使用libGDX更改Scene2D图像中的纹理?

Application Delegate 是加载登录视图的正确位置吗?

无法在 JavaFX WebView 中登录 Google