I am working on iOS application which requires to maintain a clock timer session between two devices upon acceptance of both device users?
But I am not sure how this can be achieved without getting a flaw in timing on both devices?
I have already look on following ideas:
1)Maintain state of both devices with help of Webservices or push notification so that timer on both devices will start at the same time. But if network is not working properly this approach is getting failed and there is flaw in timer on both devices.
In addition, I also want to know how can I prevent application clock remain unchanged even after changing device date and time.
Any help over this would be appreciated.
Thanks in advance.
Edit:
After implementing Bzz approach, it is fine but one thing I am still facing issue is how to calculate and maintain time taken in calling webservice from device A to send resulting network timestamp to another device B.
What can be done to handle this case?
You can use ios-ntp to get network time and calculate time offset between local and network time on both devices. When you start timer on one device, you subtract the offset from the local timestamp and send the resulting network timestamp to another device. On another device you append the local offset to the network timestamp and get the timestamp of timer start in the local time.
You can use UIApplicationDelegate.applicationSignificantTimeChange(_ application: UIApplication)
to monitor time changes on the device and recalculate the offset by updating network time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With