ios - 自动登录,AppDelegate 到 SceneDelegate,UIApplication.shared.delegate 一样!AppDelegate 被替换为?
问题描述
我在尝试设置自动登录功能时遇到问题。
我之前对根 ViewController 进行了一些研究,发现现在我需要使用 SceneDelegate 来实现自动登录功能,而不是使用 AppDelegate。但是,每当我尝试注销或登录时,以下代码都会使我的应用程序崩溃。
(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()
}
解决方案
阅读此内容->
此 SceneDelegate 来自哪里?
推荐阅读
- javascript - Web自动化登录输入框麻烦
- apache - htaccess :将所有 url 重定向到公共文件夹 exept api 文件夹中的 index.php
- cmake - 如何在 cmake 中使用 cpplint.py?
- sharepoint - 自动将文件移动到文件夹时防止文件重复
- python - 按 groupby 和 mean 绘制
- javascript - 画布对象定位问题 - JS
- php - 如何将多个表单连接到一个按钮
- django - 在 Django 中自动添加 html
- process - 将 Spring Boot 进程的名称设置为 top 命令
- bash - bash - 按值传递但没有正确的结果