4

In my app I want to get the accurate date and time , Basically, in my application there is going to be a time sensitive portion that users can not start until after a certain time.

But if I go and grab the date and time from the device, the user can easily change the date and time on their device, Settings > General > Time & Date change it here.

I also tried with GPS locations time stamp but no luck, [CLLocation timeStamp] is also give device time,

I have searched all said to use ios-ntp, but it is not when user not have internet connection,

I have refer following StackOverflow questions:

but not getting result I want,

Is there other way to get accurate/ actual time ?

NOTE : ios have to store the currentdate some where , because when i change current system date from settings , and again set to Settings > General > Time & Date > set automatically > ON it will set the current accurate date, so can we get that date ?? or some trick ?

Example :

Suppose that In device right now time is 2014-01-01 15:04:57 +0000 ( right now set automatically is ON in Settings > General > Time & Date > set automatically > ON ), now
user set set automatically > OFF and change current dateto 2014-03-02 11:14:32 +0000

SO when in app i write NSLog(@"cdate: %@",[NSDate date]); it will print

cdate: 2014-03-02 11:14:32 +0000 but what i want is to print the current actual

date that is 2014-01-01 15:04:57 +0000

Community
  • 1
  • 1
  • with regard to your original requirement, can you elaborate? that is – the nature of the task, whether the time is fixed or it depends on a previous user action, and why you cannot rely - at least once - on network connectivity. – magma Jan 01 '14 at 11:38
  • just one requirement is, get the accurate time (not a device time ) without internet connection, because i have check in iPhone to set other date and when i set date time to automatic it will load the currect time, without internet and carrier data. –  Jan 01 '14 at 11:42
  • @magma: i have some functionality in app that depends on current time , so must get the current time, not device time. and check with device time. –  Jan 01 '14 at 11:44
  • what I was suggesting is that while you're maybe focused on what you believe to be the solution to your requirement, someone could come up with a different approach altogether. by elaborating your real requirement (which is NOT retrieving the actual datetime, but rather, preventing a user from performing a given action before a given time), you would make it easier for us to see if there's a workaround. – magma Jan 01 '14 at 11:44
  • @magma: i have some functionality in app that depends on current time , so must get the current time, not device time. and match with device time. if time differnce is more than 10 mins i dont have to do that task. –  Jan 01 '14 at 11:46
  • ok, what kind of functionality? can you elaborate? – magma Jan 01 '14 at 11:46
  • That is i cant tell ( confidential),, i can tell only thing is that i have to **match the device time and current actual time** –  Jan 01 '14 at 11:48
  • @magma: i have updated question , can you please refer it.\ –  Jan 01 '14 at 12:03
  • @user203108 Have you got solution for this ? – Karthik Mandava Jan 17 '17 at 06:36

1 Answers1

2

Do you realise you are asking the impossible? If you need to get the time and you don't have network connectivity, the only place to get the time from is the device. Either you trust the device time, or you get the time from NTP. There are no other choices.

How you handle this depends on exactly why you need to get the time. If, there is functionality in your app that absolutely must not be enabled before a certain date, I would get the time from an external server and if it proves to be after the said date, set a flag in your defaults to say you have verified the date and the functionality is allowed, so you don't need to network connectivity thereafter. If the networking connectivity is not there, you don't set the flag but maybe put a message up to say that you need to connect to the Internet to enable the new functionality.

If it's just some part of a game, use device time and let them cheat if they want.

JeremyP
  • 84,577
  • 15
  • 123
  • 161
  • is it possible on jail break device?? –  Jan 02 '14 at 04:05
  • @user203108 No, it's a fundamental limitation. If you do not have a connect to the outside World, the only place you can get the time from is the device itself. – JeremyP Jan 02 '14 at 12:27