1

In my app I'm registering a NSSystemClockDidChangeNotification notification in AppDelegate method application:application didFinishLaunchingWithOptions:options.

Posted whenever the system clock is changed. This can be initiated by a call to settimeofday() or the user changing values in the Date and Time Preference panel. The notification object is null. This notification does not contain a userInfo dictionary.

Month ago it was working fine, but these days every time I suspend my app, lock my iPhone and leave it 2 minutes to pass, when opening the app, the selector method is called, which is weird to me. I didn't change the system or time, I just let the device idle.

Can anyone help me understand this? I just want to execute some code when the user manually change the system time, just in that case (tried with UIApplicationSignificantTimeChangeNotification but that doesn't help).

ricardopereira
  • 11,118
  • 5
  • 63
  • 81
Slavcho
  • 2,792
  • 3
  • 30
  • 48

2 Answers2

0

Like that: Getting iOS system uptime, that doesn't pause when asleep

But remember, this solution will fail sometimes because of out-of-sync when system tries to update time from NTP server when the Internet connection is not reachable.

Community
  • 1
  • 1
Aleksei Minaev
  • 1,488
  • 16
  • 17
0

This answer is a bit late but this is what the apple support team replied when I ask a similar question:

Part of the question I asked:

Could it be possible for the OS posted [this notification] if the time/timezone has not changed in the device?

The answer I got from them:

Absolutely [1]. It's common for a notification like this to be posted redundantly. In some cases it's triggered by a state change you can't see. For example — and I haven't tested this theory, so it's just an example of how this sort of thing can come about — this notification might be posted if the system's giant list of time zone info has changed. So, the time zone state has changed, but it's not something that affects your app.

But in other cases, a notification might be truly redundant (-: iOS is a complex system and in some cases this complex machinery generates redundant notifications, and there's no need to filter them out because…

Your app should respond to such notifications be refetching the info it cares about and updating its state based on that. If this update is expensive, keep your own copy of the previous state, compare the current system state to that, and only do the update if the stuff you care about has actually changed.

Luciano Perez
  • 101
  • 1
  • 10