自动登录,AppDelegate到SceneDelegate,UIApplication.shared.delegate为! AppDelegate被替换为?

时间:2019-11-13 20:19:14

标签: ios swift

我在尝试设置自动登录功能时遇到问题。

我之前对根ViewController进行了一些研究,发现我现在不使用AppDelegate,而是需要使用SceneDelegate来实现自动登录功能。但是,无论何时我尝试注销或登录,以下代码都会使我的应用崩溃。

(UIApplication.shared.delegate as! AppDelegate).configureInitialViewController()

我了解我已无法使用它,因为我已从AppDelegate切换到SceneDelegate。有人可以建议我使用修改后的代码登录并注销吗?

我在SceneDelegate中的代码如下。

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    configureInitialViewController()
    guard let _ = (scene as? UIWindowScene) else { return }
}

func configureInitialViewController() {
    var initialVC: UIViewController
    let storyboard = UIStoryboard(name: "Welcome", bundle: nil)

    if Auth.auth().currentUser != nil {
        initialVC = storyboard.instantiateViewController(withIdentifier: IDENTIFIER_TABBAR)
    } else {
        initialVC = storyboard.instantiateViewController(withIdentifier: IDENTIFIER_WELCOME)
    }

    window?.rootViewController = initialVC
    window?.makeKeyAndVisible()
}

2 个答案:

答案 0 :(得分:0)

在您的代码中,您未设置窗口。

lista = cursor.fetchall()[0][0]

答案 1 :(得分:0)