gpt4 book ai didi

ios - 试图将某些类型的用户路由到不同的主屏幕 Swift

转载 作者:行者123 更新时间:2023-11-28 15:23:19 26 4
gpt4 key购买 nike

我正在创建一个包含两种不同类型用户的应用程序。我希望一种类型的用户转到一个主屏幕,而另一种类型的用户转到另一个主屏幕。这是基于名为“accountType”的属性完成的,该属性在创建用户时默认设置为“reporter”,管理员可以在以后更改。我在编写 if 语句来实现这一点时遇到问题:

//create the user in Firebase
if let email = emailAddressTextField.text, let pass = passwordTextField.text{
Auth.auth().createUser(withEmail: email, password: pass, completion: { (user, error) in
if let u = user{
//user is found, go to home screen
var lastName = self.lastNameTextField.text
var firstName = self.firstNameTextField.text
var accountType = "reporter"
self.ref.child("Users").child((user?.uid)!).setValue(["email": email, "first_name": firstName, "last_name": lastName, "accountType": accountType])

let userID = Auth.auth().currentUser?.uid

//尝试让正确类型的用户访问正确的主屏幕

                if self.ref.child("Users").child((userID?.uid)!).child("accountType") = "reporter" {
self.performSegue(withIdentifier: "goToHome1", sender: self)
}
else {
self.performSegue(withIdentifier: "goToHome2", sender: self)
}

}

最佳答案

你所做的只是定义一个 Firebase 路径,你还必须观察数据库中引用该路径的值,试试这个:-

 self.ref.child("Users").child((userID?.uid)!).child("accountType").observeSingleEvent(of: .value, with: {(Snapshot) in

if let accountT = Snapshot.value as? String{

// You have retrieved the account type
// Now Segue

if accountT == "reporter"{

self.performSegue(withIdentifier: "goToHome1", sender: self)

}else{

self.performSegue(withIdentifier: "goToHome2", sender: self)

}

}else{

// There was no node found in the database
// named 'accountType'

}


}, withCancel: {(Error) in

// There was some error with the firebase call
// Handle that error

print(Error.localizedDescription)


})

关于ios - 试图将某些类型的用户路由到不同的主屏幕 Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45613854/

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