gpt4 book ai didi

ios - Firebase 按属性名称查询一个特定对象

转载 作者:行者123 更新时间:2023-11-29 00:49:13 25 4
gpt4 key购买 nike

我正在设置一个使用 Firebase 的应用。我想要做的只是在登录时从网站上获取一个用户的关联值。我已经正确设置了种子函数,但我想提取我在此处创建的用户对象:

 // MARK: - Firebase Register
func firebaseRegister() {

var allFieldsAreFilled = true

for textField in requiredTextFields {
if textField.text == "" {

allFieldsAreFilled = false

}
}

if allFieldsAreFilled {

if let email = emailTextField.text, password = passwordTextField.text, givenName = firstNameTextField.text, familyName = lastNameTextField.text, state = stateTextField.text, phoneNumber = phoneNumberTextField.text {

if password == verifyPasswordTextField.text {

if email == verifyEmailTextField.text {

FIRAuth.auth()?.createUserWithEmail(email, password: password) { (user, error) in

if error != nil {

print(error)

} else {

self.ref.child("users").child(user!.uid).setValue(

["email": email,
"password": password,
"givenName":givenName,
"familyName": familyName,
"state": state,
"phoneNumber": phoneNumber]

)
}
}
}
}

} else {

presentAlert("Please fill all fields")

}
}
}

我想通过电子邮件从用户路径中拉出一个 child 。我在使用查询示例时遇到问题。提前致谢!

最佳答案

这是我目前正在使用的代码块,如果它不存在,它还会将用户保存到我的核心数据中

self.ref.child("users").queryOrderedByChild("email").queryEqualToValue("\(email)").observeEventType(.Value, withBlock: { snapshot in

if ( snapshot.value is NSNull ) {

print("username does not exist")

} else {

if !DataController.sharedInstance.usernameExists(email) {

if let snapshots = snapshot.children.allObjects as? [FIRDataSnapshot] {

for snap in snapshots {

if let dict = snap.value as? Dictionary<String, AnyObject> {

let key = snap.key

if let givenName = dict["givenName"] as? String, familyName = dict["familyName"] as? String, email = dict["email"] as? String, password = dict["password"] as? String, state = dict["state"] as? String, phoneNumber = dict["phoneNumber"] as? String {

DataController.sharedInstance.seedUser(key, email: email, given_name: givenName, family_name: familyName, password: password, state: state, phoneNumber: phoneNumber)

}
}
}
}
}

self.currentUser = DataController.sharedInstance.fetchUserByEmail(email)

}
})

关于ios - Firebase 按属性名称查询一个特定对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38311633/

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