gpt4 book ai didi

ios - 启动 iOS 应用程序时检查用户登录

转载 作者:行者123 更新时间:2023-11-30 11:39:30 26 4
gpt4 key购买 nike

我在 iOS 中有一个应用程序,并且正在使用 firebase 进行用户登录/验证等。我希望能够登录,如果用户关闭该应用程序然后重新打开它,他们不会被迫重新-每次都登录。目前我的 AppDelegate 中有此代码:

func setRootViewController(){
if Auth.auth().currentUser != nil {
self.presentTabBar()
} else {
self.presentLoginViewController()
}
}

func presentTabBar(){

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let viewController = storyboard.instantiateViewController(withIdentifier :"myTabBar")
self.present(viewController, animated: true)
}

但是,因为这是在我的 AppDelegate 中,所以我在 self.present(viewController...) 行上收到错误,指出 AppDelegate 没有名为 self 的成员。我知道这是因为 self 仅适用于 ViewController。

如何从我的 AppDelegate 文件中实现此功能?

最佳答案

您可以使用self.present(viewController,animated: true)来代替

UIApplication.shared.keyWindow?.rootViewController?.present(viewController, animated: true, completion: nil)

关于ios - 启动 iOS 应用程序时检查用户登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49403280/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com