XCODE:如何从设备获取/验证ACCURATE时间戳 [英] XCODE: How to get/verify ACCURATE timestamp from device

查看:119
本文介绍了XCODE:如何从设备获取/验证ACCURATE时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在没有互联网连接的情况下获取NTP或准确的时间戳?我不能/不信任[NSDate date]的设备时间戳,因为它可以由用户修改,我的应用程序将被黑客入侵,只需修改系统日期&时间。



除此之外,没有获得准确的时间戳,有没有办法检查系统日期已被用户更改或未设置为自动。 p>

谢谢&请问,如果你想收集当前的信息,那么请问如果你想收集当前的信息,日期相对于特定时区,您可以使用以下行:

  //创建日历
NSCalendar * calendar = [NSCalendar currentCalendar];

//设置日历时区
[日历setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@UTC]];

//收集日期组件
NSDateComponents * components = [日历组件:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit)fromDate:[NSDate date]];

这是一个有点复杂的,但在iOS上,NSDate似乎还是一个问题,关于日光这样节省了我很多时间(双关不是意图:P)。


Is it possible to get the NTP or accurate timestamp without internet connection? I cannot take/don't trust device timestamp with [NSDate date] as it can be modify by user and my apps will be hacked by just modifying the system date & time.

Apart from this, instead of obtain accurate timestamp, is there any way to check the system date has changed by user or not set as "Automatically".

Thanks & Regards,

Weng

解决方案

If you want to gather the current date in relation to a specific time zone, you can use something along the lines of:

    //create calendar
NSCalendar *calendar = [NSCalendar currentCalendar];

//set calendar time zone
[calendar setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];

//gather date components
NSDateComponents *components = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit) fromDate:[NSDate date]];

It's a little convoluted, but there still seems to be an issue with NSDate on iOS with regards to daylight savings so this has saved me a lot of time ( pun not intended :P ).

这篇关于XCODE:如何从设备获取/验证ACCURATE时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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