本地原生iOS时间黑客证明背景倒计时器 [英] local native-iOS time-hack proof background count-down timer

查看:127
本文介绍了本地原生iOS时间黑客证明背景倒计时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一种创建本地原生iOS时间黑客证明背景倒计时器的方法,例如计算游戏中下一个奖励的倒计时时间。

I'd like a way of creating a local native-iOS time-hack proof background count-down timer, for example for counting down times for next reward in games.

对象说明:

本地

- 没有网络连接的工作

local
- Works without internet connection

native-iOS

- 我想在(最好)找到解决方案Objective-C或Swift

native-iOS
- I want to find a solution in (preferably) Objective-C or Swift

时间黑客证明

- 当用户向前/向后更改设备时间时,剩余时间保持不变

time-hack proof
- When a user changes its device time forward / backward, remaining time stays the same

背景

- 关闭/重新开启友好

background
- Shut-down / re-open friendly

倒计时器

- 一个计时器,在启动后,将提供一种检查剩余时间的方法

count-down timer
- A timer which, after start, will provide a method for checking the remaining time

我想在我的iOS游戏中使用基于时间的奖励系统,只需将设备时间向前移动就不会轻易破解。

I'd like to have a time-based reward system in my iOS game, which won't be easily hackable just by moving the device time forward.

最初,我想他不可能继续使用 [NSDate date] savedDate ,将它们进行比较以查找已用时间。然而,最近我遇到了一个使用此功能的游戏: Crossy Road 。据我所知,这是一款Unity游戏,但是我怀疑在Unity项目中可以使用的这种有点普遍的功能是在iOS上通过Objective-C或Swift访问的。

Originally, I thought this was not possible and kept using [NSDate date] and savedDate, comparing them together to find elapsed time. Recently, however, I came across a game which uses this feature: Crossy Road. That is a Unity game, as far as I know, but I doubt that a somewhat common feature like this available in Unity project which is compiled into an iOS app is not accessible on iOS via Objective-C or Swift.

他们提供定时奖励系统,每6个小时一次,并且,据我测试,它不会通过更改设备时间来破解。它也适用于没有互联网连接。 (如果你没有连接,我不确定它是否有效,但是当我连接,断开连接并尝试使用黑客时,它不起作用。)

They provide a timed reward system, once per every 6 hours, and, as far as I tested, it's not hackable by changing the device time. It also works without an internet connection. (I'm not sure if it works if you don't ever connect, but when I connected, disconnected, and tried to use the hack, it didn't work.)

推荐答案

您可以使用当前系统正常运行时间( mach_absolute_time())。使用 CACurrentMediaTime()可以轻松访问此函数,并在几秒钟内轻松返回。然后你可能需要设置某种间隔来检查这个值。这当然可以使用NSDate来完成,因为它不是由用户设置时钟前进触发的问题。在重新启动时,只需保存起始值并在重新启动后将其用作偏移量。

You could use the current system uptime (mach_absolute_time()). This function is easily accessible using CACurrentMediaTime() which returns it handily in seconds. Then you probably have to set up some kind of interval to check this value. This can of course be done using NSDate since it's not a problem that it gets triggered by the user setting the clock forward. When it comes to restarts, simply save the start value and use that as an offset after reboot.

唯一的缺点是它不计算设备的时间关闭,但这些天没有人转动手机通常不是什么大事。

The only drawback is that it doesn't count the time the device is turned off but that's generally not a big deal these days when no one turns of their phones.

要获得实际的计时器功能,只需在开始时保存值然后定期检查预计的最终价值,可能随着结束的方式逐渐增加分辨率。

To get the actual timer function, simply save the value at the start and then check it regularly against the projected end value, perhaps with increasing resolutions as the end approaches.

这篇关于本地原生iOS时间黑客证明背景倒计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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