我正在开发一个社交媒体应用,我想将帖子上传到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!")
}
}
}
}
答案 0 :(得分:0)
您的childByAutoId
已复制,请尝试使用setValue
而不是updateChildValues
。
private var _REF_NOW = DB_BASE.child("now")
REF_NOW.childByAutoId().setValue(["Title": title, "Id": uid,
"Description": description])