简体   繁体   中英

Firebase completion block

I'm having a strange issue with Firebase. I'm saving data to the server but the completion block is never fired:

        //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")

        })

The data is saved perfectly on the Firebase server, but the completion block is never fired.

I've tried wrapping the callback on the main thread, and that doesn't make a difference:

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

Has anyone else seen this before?

The code works, and the block is called and prints to the console with the following modifications:

//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")

})

I would investigate the variables; in particular the reference that used to build the userRef.

my implementation about the updateChildValues withCompletionBlock:

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

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

and its working absolutely fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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