iOS中是否有可以使用的时钟,用户无法更改 [英] Is there a clock in iOS that can be used that cannot be changed by the user

查看:115
本文介绍了iOS中是否有可以使用的时钟,用户无法更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设计一个实时事件发生的系统,我想将它们与时钟同步。 [NSDate date] 通常可以,但用户可以更改此设置并欺骗系统。我需要的是一个时钟,我可以从相对时间(例如64位计数器) - 我不需要绝对时间(或一天中的时间等)。

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 change this and cheat the system. All I need is a clock that I can take relative times from (a 64-bit counter for example) - I don't need absolute time (or time of day etc).

我可以使用这样的API吗?

Is there such an API I can use?

编辑:我还想补充一点,这个时钟需要在应用程序的会话上保持持久。

I would also like to add that this clock needs to be persistent over sessions of the application.

推荐答案

如果您只需要一个时钟来测量单调增加的事件,您可以获得当前系统的正常运行时间ala clock_gettime(CLOCK_MONOTONIC)。如果重新启动设备有问题,只需保存最后使用的值,并在下次启动时使用上次保存的值作为偏移量。这里的问题可能是,如果他们实际上关闭了设备,它将不计算那个时间。但如果你担心用户加快时间,他们就不能这样做,只会减慢速度。

If all you need is a clock to measure events as monotonically increasing, you could just get the current system uptime ala clock_gettime(CLOCK_MONOTONIC). If restarting the device is a problem, just save the last value used and at next launch use the last saved value as an offset. The Problem here may be that if they actually shut the device off, it won't count that time. But if you're worried about the user speeding up time, they can't do that, only slow it down.

这篇关于iOS中是否有可以使用的时钟,用户无法更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆