gpt4 book ai didi

ios - Firebase 实时数据库帖子

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

我正在开发一款社交媒体应用,我想将帖子上传到 Firebase,但它不会显示在实时数据库中

let DB_BASE =  Database.database().reference()
private var _REF_NOW = DB_BASE.child("now").childByAutoId()

var REF_NOW: DatabaseReference {
return _REF_NOW
}

func uploadPost(withTitle title: String, forUID uid: String,
withDescription description: String, sendComplete: @escaping (_ status:
Bool) -> ()) {
REF_NOW.childByAutoId().updateChildValues(["Title": title, "Id": uid,
"Description": description])
sendComplete(true)
}

@IBAction func postPressed(_ sender: Any) {
if textfield.text != nil && textview.text != nil && textview.text != ""
{
postBtn.isEnabled = false
DataService.instance.uploadPost(withTitle: textfield.text!, forUID:
(Auth.auth().currentUser?.uid)!, withDescription: textview.text) {
(isComplete) in
if isComplete {
self.postBtn.isEnabled = true
self.dismiss(animated: true, completion: nil)
} else {
self.postBtn.isEnabled = true
print("There was an error!")
}
}
}
}

最佳答案

您的 childByAutoId 重复,请尝试使用 setValue 而不是 updateChildValues

private var _REF_NOW = DB_BASE.child("now")

REF_NOW.childByAutoId().setValue(["Title": title, "Id": uid,
"Description": description])

关于ios - Firebase 实时数据库帖子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51434376/

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