Frage

I'm making a Turn-Based game, and trying to figure out when the last turn happened. I get it to work by doing this:

NSDate *lastTurn = [NSDate date]; (When sending turn)

... And then calculate the difference for the next player when it's his/her turn:

NSTimeInterval *diff = [lastTurn timeIntervalSinceNow];

This works great if both users have the same time settings. But if one player have their iphone set to a different timezone or have the time set all wrong, the result will be wrong.

How can i fix this?

Many thanks

War es hilfreich?

Lösung

Use GMT time instead of local time.

Maybe something like this (I haven't tried):

NSInteger sec = [[[NSCalendar currentCalendar] timeZone] secondsFromGMT];

Andere Tipps

I think @StefanB has the answer, but I would also consider this. Can someone "cheat" by deliberately changing the clock on their phone? even with GMT. Another thought is that being turn based, presumably you are going to have a central server which manages the game. In which case you can avoid this whole problem by using the servers time which is common to all players and cannot be manipulated by them.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top