呈现视图控制器太慢
Presenting View Controller is too slow
我已经在我的 Swift 应用程序中实现了 Firebase Google 登录。如果它已经是登录用户,我想先检查一下。我是这样做的:
override func viewDidLoad() {
super.viewDidLoad()
GIDSignIn.sharedInstance()?.presentingViewController = self
GIDSignIn.sharedInstance().delegate = self
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(false)
if Auth.auth().currentUser != nil {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "feedVC")
vc.modalPresentationStyle = .fullScreen
self.present(vc, animated: false)
}
}
现在我的问题是:它按我想要的方式工作,但速度很慢。在我的主页显示之前,我仍然可以快速查看登录屏幕。
现在如果我想将 currentUser 检查添加到 viewDidLoad,应用程序不会检查用户之前是否已经登录。
有什么建议吗?
在主线程上执行
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(false)
if Auth.auth().currentUser != nil {
DispatchQueue.main.async {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "feedVC")
vc.modalPresentationStyle = .fullScreen
self.present(vc, animated: false)
}
}
我已经在我的 Swift 应用程序中实现了 Firebase Google 登录。如果它已经是登录用户,我想先检查一下。我是这样做的:
override func viewDidLoad() {
super.viewDidLoad()
GIDSignIn.sharedInstance()?.presentingViewController = self
GIDSignIn.sharedInstance().delegate = self
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(false)
if Auth.auth().currentUser != nil {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "feedVC")
vc.modalPresentationStyle = .fullScreen
self.present(vc, animated: false)
}
}
现在我的问题是:它按我想要的方式工作,但速度很慢。在我的主页显示之前,我仍然可以快速查看登录屏幕。
现在如果我想将 currentUser 检查添加到 viewDidLoad,应用程序不会检查用户之前是否已经登录。
有什么建议吗?
在主线程上执行
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(false)
if Auth.auth().currentUser != nil {
DispatchQueue.main.async {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "feedVC")
vc.modalPresentationStyle = .fullScreen
self.present(vc, animated: false)
}
}