0

I need to be able to determine if the users phone date/time is set correctly. Just in case the user has been playing Candy Crush or something similar where they may change their date settings.

Is there any local methods that can confirm the time is correct. If not can someone recommend a reliable online service to validate time.

Thanks

user346443
  • 4,672
  • 15
  • 57
  • 80
  • Keep in mind that the device may be an iPad or iPod and hence not have a phone connection to use the cell time service. Also, of course, it's not a given that an internet connection is available. – Hot Licks Feb 19 '15 at 03:23
  • possible duplicate of [How can I get the real time in iPhone, not the time set by user in Settings?](http://stackoverflow.com/questions/1443350/how-can-i-get-the-real-time-in-iphone-not-the-time-set-by-user-in-settings) – Hot Licks Feb 19 '15 at 03:27
  • Because it's always necessary to ask, what have you tried? – BobbyScon Feb 19 '15 at 03:31

2 Answers2

0

Date and time on the phone is always relevant to the date/time in the users settings. The only time validations you can do consists of requesting for a valid time from an external source (like an API call) and match that time against the time the user has in the settings.

I'm unfamiliar with regular APIs that provide this, but I'm sure it's a google away.

TheCodingArt
  • 3,436
  • 4
  • 30
  • 53
0

I think there are some inherent flaws with your question, as how would your app determine what the real date/time should be? The user would need to be connected to data in order to fully verify, so if this is for a subscription or trial period, they'd find a way around it. If you're just looking for date, then I don't think it's terribly difficult, but time will be determined by time zone, if the user allows the device to select the "correct" one, daylight savings, etc.

Best suggestion I have at the moment is to write a query in your app that pings one of the global clocks to verify date, adjust the result based on the time zone of the device, then compare to what the device's date/time is set to.

Get the device's date/time (NSDate uses the device's clock):

-(void)targetMethod:(id)sender
{
  NSString *currentTime = [dateFormatter stringFromDate: [NSDate date]];
  timeLabel.text = currentTime;
}

Here's an example of an API for determining the correct time to compare NSDate to: http://worldtime.io/api/geo

BobbyScon
  • 2,537
  • 2
  • 23
  • 32
  • The fact that the "worldtime.io" api is no longer available demonstrates the risk of using a third party API for this. I'd expect the NIST API to be more reliable, but it sure would be nice if they provided an equally reliable HTTP JSON API. – Doug Feb 03 '22 at 17:02