gpt4 book ai didi

ios - Firebase 读取返回 null

转载 作者:行者123 更新时间:2023-11-28 16:07:52 25 4
gpt4 key购买 nike

在我的应用程序中,我试图从 Firebase 数据库获取用户信息,但它始终返回 null。这是我从数据库中读取当前用户信息的代码

func workWithDataBase(){
let email = "test@gmail.com"
let password = "test23"


FIRAuth.auth()?.signIn(withEmail: email, password: password, completion: { (user, error) in
if error != nil {
print(error)
return
} else {
print("SIGNED IN\n")

let uid = FIRAuth.auth()?.currentUser?.uid

FIRDatabase.database().reference().child("users").child(uid!).observeSingleEvent(of: .value, with: { (snapshot) in
print(snapshot)
}) {
(error) in
print(error.localizedDescription)
}
}
})
}

这是 Firebase 数据库的输出和屏幕截图 enter image description here

enter image description here

我的问题是,如果电子邮件和姓名字段不为空,为什么“observeSingleEvent”方法返回 null?我该如何解决这个问题?

最佳答案

试试这个:-

 FIRDatabase.database().reference().child("user").child(FIRAuth.auth()!.currentUser!.uid).observeSingleEvent(of: .value, with: { (snapshot) in
print(snapshot)
}) {(error) in
print(error.localizedDescription)
}

关于ios - Firebase 读取返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39976488/

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