How do I get a server timestamp from Firebase's iOS API?

后端 未结 4 677
迷失自我
迷失自我 2020-12-25 15:23

I have an iOS app that uses Firebase and currently has a few dictionaries with keys that are NSDate objects. The obvious issue with this is that NSDate draws from the devic

4条回答
  •  一个人的身影
    2020-12-25 15:38

    As of Firebase 4.0 you can use ServerValue.timestamp()

    for example:

        let ref = Database.database().reference().child("userExample")
        let values = ["fullName": "Joe Bloggs", "timestamp": ServerValue.timestamp()] as [String : Any]
    
        ref.updateChildValues(values) { (err, ref) in
    
            if let err = err {
                print("failed to upload user data", err)
                return
            }
    
        }
    

提交回复
热议问题