2

i am on way to making game. and i am trying to solve an issue about time.

gamer get life (when all rights of playing finished) every ten minutes. (at the same time i will sell a life as an in-app like candy crush). game is offline playable. i am getting time and save it when user killing app . When he/she opens game getting current time and giving life by making date subtraction. here is an issue that;

when user kills app, adjust time to 1 hour later and opens the game again (problem goes and i am giving lifes).

is there any way to solve this problem. is there any time source (without online access) that user can not change and i can retrieve correct time.

ps: i will code the game in iOS environment. iOS specific answers will be appreciated.

meth
  • 1,867
  • 2
  • 18
  • 33
  • I've wanted to know if there is a solution to this too. The best I thought of is that if you save the date that the user closes the app, and if they open it on a date previous to the close, you can detect suspicious activity that way. But that only works after the fact and isn't very reliable. – Jimmy Lee Mar 30 '13 at 22:43
  • saving the latest time is a way but still not reliable as you say. – meth Mar 30 '13 at 22:49
  • yes i now find that question and flagged mine – meth Mar 31 '13 at 00:07

2 Answers2

0

I do not believe that there is a solution.

What you want is a relative time, so you could think about firing an NSTimer after a certain interval, but even that won't work because such timers will fail or die when the app is in the background (or killed).

Ultimately unless you utilize an off-device storage method you are beholden to the user's date management. Whatever absolute time method you use (such as CFAbsoluteTimeGetCurrent) it will be dependent on the system clock that the user can modify.

Rikkles
  • 3,240
  • 1
  • 16
  • 22
0

I would use the "monotonic time" given from the real clock time unit. On linux this is usually done by using clock_gettime(CLOCK_MONOTONIC, &timespec);. On mac/ios I think mach_absolute_time() is the function you are looking for. See one of these posts for further reading

clock_gettime alternative in Mac OS X

Monotonic clock on OSX

CACurrentMediaTime() uses mach_absolute_time(). So it should be your best friend since it is not possible to change by the user. Except for it will be reset on reboots (at least on mac). It would be best in your case if the mach_absolute_time wasn't reset on reboots...

Community
  • 1
  • 1
hfossli
  • 21,612
  • 9
  • 111
  • 127