Firebase完成块

时间:2016-03-11 17:41:36

标签: ios swift firebase

我对Firebase有一个奇怪的问题。我将数据保存到服务器,但永远不会触发完成块:

        //get the current user and update the info
        let fbID:String = userData?.objectForKey("facebookID") as! String;
        let ref = Firebase(url:self.FIREBASE_URL)
        let userRef = ref.childByAppendingPath("user").childByAppendingPath(fbID)
        let update = ["work" : work , "school" : school, "description": about]

        userRef.updateChildValues(update, withCompletionBlock: { (error:NSError?, ref:Firebase!) in
            print("This never prints in the console")

        })

数据完全保存在Firebase服务器上,但永远不会触发完成块。

我已经尝试在主线程上包装回调,但这并没有什么区别:

        userRef.updateChildValues(update, withCompletionBlock: { (error:NSError?, ref:Firebase!) in
    dispatch_async(dispatch_get_main_queue()) {
            print("This never prints in the console")
        }
        }) 

之前有其他人见过吗?

2 个答案:

答案 0 :(得分:1)

代码工作,调用块并通过以下修改打印到控制台:

//get the current user and update the info
let work:String = "work value"
let school:String = "school value"
let about:String = "about value"
let fbID:String = "key_0"
let userRef = myRootRef.childByAppendingPath("user").childByAppendingPath(fbID)
let update = ["work" : work , "school" : school, "description": about]

userRef.updateChildValues(update, withCompletionBlock: { (error:NSError?, ref:Firebase!) in
    print("This never prints in the console")

})

我会研究变量;特别是用于构建userRef的引用。

答案 1 :(得分:0)

关于updateChildValues withCompletionBlock的实现:

db.child(id).updateChildValues(dict, withCompletionBlock: {error, ref in

            if error != nil{
                print("ERROR")
            }
            else{
                print("ok")
            }
        })

它的工作非常好。