不同帐户的ViewController登录页面不起作用



我想实现firebase关键:是否,

价值:"admin"进入view "adminVC"价值:"知道;在视野中"MainTabBarController"

没有此键:security - check into view "SignUpViewControllerID">

下面是我目前的代码,但它不工作,希望有人能给我一些建议,谢谢

Database.database().reference().child("ID/(self.uid)/Profile/Safety-Check").observeSingleEvent(of: .value, with: {
(snapshot) in
let cheak = "Safety-Check"
if cheak == "admin" {

if let viewController = self.storyboard?.instantiateViewController(withIdentifier: "AdminVC") {
GetWindow()?.rootViewController = viewController
GetWindow()?.makeKeyAndVisible()
}
if cheak == "ON" {
if let viewController = self.storyboard?.instantiateViewController(withIdentifier: "MainTabBarController") {
GetWindow()?.rootViewController = viewController
GetWindow()?.makeKeyAndVisible()

}else{
if let viewController = self.storyboard?.instantiateViewController(withIdentifier: "SignUpViewControllerID") {
GetWindow()?.rootViewController = viewController
GetWindow()?.makeKeyAndVisible()

(解决)问题2。黄色警告:'keyWindow'在iOS 13.0中已弃用:不应该用于支持多个场景的应用程序,因为它在所有连接的场景中返回一个键窗口。

我应该如何修改它来解决这个问题?

UIApplication.shared.keyWindow?.rootViewController = viewController

使用下面的函数获取窗口:

func GetWindow() -> UIWindow? {

if #available(iOS 13.0, *) {
let sceneDelegate = UIApplication.shared.connectedScenes
.first?.delegate as? SceneDelegate
let appDelegate = UIApplication.shared.delegate as? AppDelegate
return sceneDelegate?.window ?? appDelegate?.window
} else {

let appDelegate = UIApplication.shared.delegate as? AppDelegate
return appDelegate?.window
}
}

使用以上功能:

if let window = GetWindow() {}

关于你的情况:

GetWindow()?.rootViewController = viewController

所以替换这些行:

UIApplication.shared.keyWindow?.rootViewController = viewController
self.dismiss(animated: true, completion: nil)

:

GetWindow()?.rootViewController = viewController
GetWindow()?.makeKeyAndVisible()

,你不需要把它设置一个新的根视图控制器代码。

相关内容

  • 没有找到相关文章

最新更新