2

Problem: I know about the method applicationSignificantTimeChange to detect manual time change. But the method documentation says:

Examples of significant time changes include the arrival of midnight, an update of the time by a carrier, and the change to daylight savings time. The delegate can implement this method to adjust any object of the application that displays time or is sensitive to time changes.

So it detects not only a manual time change, but arrival of midnight as well. In my application, that will create a problem as the user will see an alertbox:

You have change the time. Please revert back to actual time.

even when he resumes the app after midnight (or may be he minimized the app and went to sleep. Next day he wakes up, resumes the app and surprisingly gets the time change notification).

Question: How to show the alert only on manual time change and not on arrival of midnight ?

utsabiem
  • 920
  • 4
  • 10
  • 21
  • Who/What is performing the 'manual time change' that you hope to alert your User about? – GoZoner Jul 03 '13 at 01:44
  • your alert won't come up unless the app is open or semi open/minimized if you could use applicationSignificantTimeChange for the results you want but from reading that description I do not see it stating it detects a user changing the time....though it could. I know a very popular app named CSR Racing has a issue with cheating because of the user changing the time you get bonus coins that take a month to get. My approach, if I needed protection from this, would be check with an outside source/webserver time from my app launch and compare with users time and then i would have a comparison. – rezand Jul 03 '13 at 04:58
  • 1
    For example, the user minimizes the app, then changes time from settings. After that, if the user opens/resumes the app, he will get notification through applicationSignificantTimeChange method. But he will also get that if he does not change time, but arrival of midnight happens. I want to avoid that. – utsabiem Jul 03 '13 at 16:21
  • How you call that method, i tryed by calling it in `[UIApplicatin sharedApplication]` but it's not defined. Where i should call it, or it's a delegate? – IgniteCoders Apr 03 '14 at 11:08

3 Answers3

1

Just use NSSystemClockDidChangeNotification Apple doc link

Slavcho
  • 2,792
  • 3
  • 30
  • 48
1

I have used a variant of the remote server time check for one or a few years now. It works pretty well, on iOS.

  1. Fetch remote time.

  2. In your time checking class, store the offset between remote time and device time, store that in a simple NSTimeInterval variable.

  3. Now you can get "real time" at any time from your time checking class, because it can take the current device time and just add the stored offset and you will have the real time, all the time.

  4. Whenever the app backgrounds, you will need to delete the stored offset, because the user can be fiddling with the time settings.

  5. For every app foreground event, you will have to perform 3. again. Go get remote time again. Deny any calls to get real time until you have that offset again. Any calls depending on the real time existing will have to fail gracefully in those events where real time has not yet been fetched.

  6. Now the offset you get should/can be compared with the offset you got last time. Decide a threshold, like 15 seconds. If the offset change from last time exceeds that threshold, the user likely changed time manually. This is a useful event for me. Of course even though the user can change the device time I will always have real time handy (most of the time).

Afaik, I always work with UTC time stamps to avoid any locale troubles.

Jonny
  • 15,955
  • 18
  • 111
  • 232
0

Always its better to check such things with server time.

Follow below steps.

  1. Fetch the server time and convert to current locale.

  2. Check mobile time using current locale.

  3. If they are not same, that means user has changed the time.

Let me know if this is clear or not.

Fahim Parkar
  • 30,974
  • 45
  • 160
  • 276