1

我正在制作一个回合制游戏,并试图找出最后一回合发生的时间。我通过这样做使它工作:

NSDate *lastTurn = [NSDate date];(发送回合时)

...然后在轮到他/她时计算下一个玩家的差异:

NSTimeInterval *diff = [lastTurn timeIntervalSinceNow];

如果两个用户具有相同的时间设置,这将非常有用。但是,如果一个玩家将他们的 iphone 设置为不同的时区或时间设置错误,则结果将是错误的。

我怎样才能解决这个问题?

非常感谢

4

2 回答 2

1

使用 GMT 时间而不是本地时间。

也许是这样的(我没试过):

NSInteger sec = [[[NSCalendar currentCalendar] timeZone] secondsFromGMT];
于 2012-03-05T23:27:12.007 回答
0

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.

于 2012-03-05T23:34:17.213 回答