简体   繁体   中英

Getting correct time when user change device time manually?

I am using Firebase as backend for my iOS application. and when user change his device time manually in settings he can make action in future times.

so I searched internet, and I did not see any native solution in Swift to detect real time.

and I am wondering is the problem can be solve by Swift code or using Firebase SDK sever time?

[Edit] how we can show correct time in UI not device time?

Use ServerValue.timestamp() in firebase.

For an example:

    let ref = Database.database().reference().child("userExample")
    let values = ["firstName": "Joe", "lastName": "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
        }

    }

More more information check the documentation .

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