Sign in to follow this  
Nairb

iPhone Timer Drift

Recommended Posts

I'm trying to detect when the user advances their clock, since that's an easy way to cheat some game mechanics. The cheat detection only needs to work in the case where the user doesn't shut down the game.

The current implementation looks a little like this:
[list][*]At the beginning of the game, save the time the game started using two timers - the "user modifiable clock" ( [NSDate timeIntervalSinceReferenceDate] ) and the "system clock" (mach_absolute_time or CACurrentMediaTime). These two timers will have different values but should grow at the same rate.[*]Every frame, diff the current values of the respective timers against the times we saved.[*]If the two differences are too far apart (within some margin of error), we know the clock has been tampered with, since the only way that should be possible is if the user changed their clock.[/list]

This doesn't quite work out, though. On some devices, mach_absolute_time grows faster than [NSDate timeIntervalSinceReferenceDate]. This isn't behavior I'd expect - they should both be determining, well, time, but I guess one of these timers is not terribly accurate.

Has anyone encountered this? It's a pretty niche problem.

Cheers,
--Brian

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this