Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to maintain clock session between two different devices?

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?

like image 693
Akshay Sunderwani Avatar asked Apr 16 '16 05:04

Akshay Sunderwani


1 Answers

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.

like image 144
bzz Avatar answered Oct 26 '22 23:10

bzz