iOS开发-检查上网时间 [英] iOS Development - Check Internet Time

查看:31
本文介绍了iOS开发-检查上网时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,该应用程序每5分钟补充一次生命.检查自上次填充后的时间的最佳方法是什么,以使用户无法通过更改设备上的时间来欺骗系统?

I am developing an app that has refills lives every 5 minutes. What is the best way to check the time since the last refill so that the user cannot trick the system by changing the time on their device?

例如,请看《 Candy Crush》.更改那里的系统时间会给您额外的生命,而这正是我需要避免的.

For an example, look at Candy Crush. Changing the system time on there gives you extra lives, and this is what I need preventing.

推荐答案

NSURL *url = [NSURL URLWithString:@"http://www.timeapi.org/utc/now"];
NSString *str = [[NSString alloc] initWithContentsOfURL:url usedEncoding:Nil error:Nil];

str = [str stringByReplacingOccurrencesOfString:@"T" withString:@" "];
str = [str stringByReplacingOccurrencesOfString:@"+01:00" withString:@""];

NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-MM-dd hh:mm:ss"];
NSDate *date = [dateFormat dateFromString:str];

这篇关于iOS开发-检查上网时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆