Is there a clock in iOS that can be used that cannot be changed by the user

后端 未结 6 1083
长发绾君心
长发绾君心 2020-11-30 02:52

I am trying to design a system where real-time events happen and I want to synchronise them to a clock. [NSDate date] would normally be ok but the user could c

6条回答
  •  無奈伤痛
    2020-11-30 03:13

    I think mach_absolute_time() may be what you'll want. There is quite a bit of information here: http://developer.apple.com/library/mac/#qa/qa1398/_index.html

    It is basically a counter of the number of ticks since the device started. This will be reset on reboot but other than that it is a monotonically increasing counter.

    You can keep the last value of the counter around and deal with it if the counter has decreased since the last time (the device was restarted). In this case you can add the last known value to the current value to get a lower bound of the time that has elapsed, all you'd lose is the time between the last session and the device shut down, you would keep the time between the reboot and the next session though.

提交回复
热议问题