2017-07-31 12 views
1

当移动是无效的日期,你怎么可以找到编程,改变在iOS设备时(设备是否在过去/将来的时间)找出在iPhone设备的无效日期

+0

https://stackoverflow.com/questions/7362199/iphone-correct-way-for-getting -current-date-and-time-for-a-place-time-timez https://stackoverflow.com/questions/30529627/check-if-the-device-datesettings-is-automatic-in-ios 如果你在你的应用中有服务器通信,那么您可以使用app时间与服务器的当前时间进行交叉检查。 – Ellen

+0

询问公共时间服务器的有效日期。 – antonsergeev88

回答

1

也许你可以使用库,可以从时间服务器获取日期和时间。

图书馆https://github.com/jbenet/ios-ntp将为你做同样的工作。

用法:

#import "ios-ntp.h" 

@interface ntpViewController : UIViewController <NetAssociationDelegate> 

@end 

@implementation ntpViewController 
- (void)viewDidLoad { 
    [super viewDidLoad]; 

    netAssociation = [[NetAssociation alloc] 
    initWithServerName:[NetAssociation ipAddrFromName:@"time.apple.com"]]; 
    netAssociation.delegate = self; 
    [netAssociation sendTimeQuery]; 
} 

- (void) reportFromDelegate { 
    printf("time offset: %5.3f mSec", netAssociation.offset * 1000.0]; 
} 

在这里获得更多的信息和参考:

https://github.com/jbenet/ios-ntp

0

必须维护服务器那。将设备当前时间与服务器时间进行比较。

0

有许多公共API会给你一个用户的当前时间。比较收到的时间和用户的时间,你可以成功地知道用户是否改变了他的时间或不。请注意,由于时间因国家而异,因此您必须了解用户的位置。

希望这会有所帮助!