繁体   English   中英

Firebase实时数据库帖子

[英]Firebase real time database posts

我正在开发一个社交媒体应用,我想将帖子上传到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])

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM