1

When mobile is in invalid date, how can I find programmatically, the changes in iOS device time (whether device is in past/future time)

KP26
  • 43
  • 1
  • 1
  • 8
  • https://stackoverflow.com/questions/7362199/iphone-correct-way-for-getting-current-date-and-time-for-a-given-place-timez https://stackoverflow.com/questions/30529627/check-if-the-device-datesettings-is-automatic-in-ios if you have server communication in your app, then you can cross check with server's current time with app time. – Ellen Jul 31 '17 at 10:34
  • Ask public time server for valid date. – antonsergeev88 Jul 31 '17 at 10:36

3 Answers3

1

May be you can use library that can fetch the date and time from a time server.

Library https://github.com/jbenet/ios-ntp wil do same job for you.

Usage:

#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];
}

Check here for more information and reference:

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

Ronak Chaniyara
  • 5,335
  • 3
  • 24
  • 51
0

You have to maintain a server for that. Compare device current time with your server time.

Torongo
  • 1,021
  • 1
  • 7
  • 14
0

There are many public APIs that will give you the current time for a user. Compare the time received to the time the user have and you can successfully know if the user changed his time or no. Take note that you have to know the users location since time differ from one country from another.

Hope this helps!

Mohamad Bachir Sidani
  • 2,077
  • 1
  • 11
  • 17