Firebase修改childByAutoID

时间:2017-03-20 04:07:47

标签: ios swift firebase swift3 firebase-realtime-database

是否可以通过自动ID更新孩子?这就是我的聊天室设置,但问题是我每次更新用户照片时都没有更改,因为照片是从childByAutoId分配和接收的。任何提示?

enter image description here

enter image description here

//Get Data from database resend to database
        if let userId = userID {
        ref.child("Users").child(userID!).observeSingleEvent(of: .value, with: {(snapshot) in

        let snapDict = snapshot.value as? NSDictionary
        let username = snapDict?["Username"] as? String ?? ""
        let firebaseUserPhotoURL = snapDict?["photo_url"] as? String ?? ""
        let userRank = snapDict?["user_rank"] as? String ?? ""

        let now = Date()
        let dateFormatter = DateFormatter()
        dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
        let nowString = dateFormatter.string(from: now)


        //Update general_room information about user
        ref.child("general_room").childByAutoId().setValue(["user_name": username, "uid": userId, "Message" : message, "time_stamp" : nowString, "photo_url" : firebaseUserPhotoURL])

0 个答案:

没有答案