0

我试图在我的场景委托中自动登录后切换屏幕,一切正常,除了我的启动屏幕出现 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 }
    }```
4

1 回答 1

1

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

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

于 2020-08-03T22:09:15.163 回答