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

查看:11
本文介绍了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天全站免登陆