local native-iOS time-hack proof background count-down timer

后端 未结 2 999
日久生厌
日久生厌 2021-02-13 12:52

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.

Ex

2条回答
  •  梦如初夏
    2021-02-13 13:35

    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.

提交回复
热议问题