【问题标题】:Firebase real time database postsFirebase 实时数据库帖子
【发布时间】:2018-08-02 04:33:08
【问题描述】:

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

【问题讨论】:

    标签: ios swift firebase


    【解决方案1】:

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

    private var _REF_NOW = DB_BASE.child("now")
    
    REF_NOW.childByAutoId().setValue(["Title": title, "Id": uid, 
    "Description": description])
    

    【讨论】:

    • 它没有工作它给了我:setValue: 或 removeValue: at /now/-LHpftdYz6dKVslftJrN failed: permission_denied
    • 如何将数据库规则更改为 { "rules": { ".read": true, ".write": true } } 用于开发目的
    猜你喜欢
    • 2021-12-15
    • 2018-09-14
    • 2020-07-05
    • 2021-07-01
    • 1970-01-01
    • 2019-05-24
    • 1970-01-01
    • 1970-01-01
    • 2021-06-14
    相关资源
    最近更新 更多