简体   繁体   English

如何在iOS Swift中检查设备时间是否正确

[英]How to check device time is correct or not in iOS Swift

I am making a quiz app in which time is a very important factor. 我正在制作一个测验应用程序,其中时间是非常重要的因素。 at particular time suppose at 11:00 AM game will start. 在特定时间,假设游戏将在11:00 AM开始。 so I am displaying countdown timer based on device time and 11:00 AM. 因此我要根据设备时间和11:00 AM显示倒数计时器。

but a user can change their device time then the game will not synchronous between all users. 但是用户可以更改设备时间,则游戏将无法在所有用户之间同步。

Is there anyways I could restrict a user to change time from the device setting or is there any other ways to check the correct time in iOS swift application. 无论如何,我是否可以限制用户从设备设置更改时间,或者是否有其他方法可以在iOS swift应用程序中检查正确的时间。

If I were in your shoes, I would keep the client synced with server on an interval. 如果我不知所措,则可以使客户端与服务器保持一定的间隔同步。 Like sending requests to the server every few seconds, which contains the data that contains the last updates of the user answers. 就像每隔几秒钟向服务器发送一次请求一样,其中包含的数据包含了用户答案的​​最新更新。 Then trace the answers and updates based on these client requests "on the server-side". 然后基于“在服务器端”上的这些客户端请求跟踪答案和更新。 That is what I mean by internally, You should check everything on the server-side. 这就是我内部的意思,您应该检查服务器端的所有内容。 Then for example, you just simply reject the answers that are received after the end of the quiz. 然后,例如,您只是简单地拒绝了测验结束后收到的答案。

For just accepting answers that are provided in time, you don't need an interval. 如果只接受及时提供的答案,则无需间隔。 Just send a request when a new answer is provided or an answer is edited. 提供新答案或编辑答案后,只需发送请求即可。

The interval based syncing, has the advantage that user interface may also always be updated according the server time. 基于间隔的同步的优势在于,用户界面也可以始终根据服务器时间进行更新。 You could fill the gaps using an interval function on the client, but everything will be updated and in sync with the server on intervals. 您可以使用客户端上的间隔功能来填补空白,但是所有内容都将在间隔上更新并与服务器同步。 You could also track any problems this way, like for example disconnection and reconnection. 您还可以通过这种方式跟踪任何问题,例如断开连接和重新连接。 Changes in the network (for cheating purposes) and etc. 网络变化(作弊目的)等

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM