0

I am having an issue with the timezone/time change in the app. Apparently, the OS post a notification NSSystemTimeZoneDidChange even though the time/timezone has not changed on the device, I mean, the user or the OS has not changed the time/timezone at all.

Could it be possible then the OS posted a push notification NSSystemTimeZoneDidChange if the time/timezone has not changed in the device?

I am using this line to observe the post.

NotificationCenter.default.addObserver(self, selector: #selector(timeZoneChanged(_:)), name: NSNotification.Name.NSSystemTimeZoneDidChange, object: nil)

Edit on 20/01/2022

This is the answer I got from Apple support team:

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
  • Are you saying that when your location/timezone changes it doesnt post a timezone change notification ? Or are you setting a fixed timezone manually? – Leo Dabus Jan 19 '22 at 17:46
  • no, I am getting a post from NSSystemTimeZoneDidChange when the time/timezone has not changed at all. I am asking if this can be even possible. An user asked the same in here: https://stackoverflow.com/questions/29533307/nssystemclockdidchangenotification-acts-weird-when-app-wakes-up – Luciano Perez Jan 19 '22 at 18:30
  • I guess my first question would be "who cares?" You get the events you get and you respond appropriately. If you receive this event and there is nothing to do, do nothing. – matt Jan 19 '22 at 18:34
  • We do care. We have a crash in our app and we proved this is happening due the time has changed (we have a feature that does something stuff when the time changes in the app) The customer is saying they did not change the time and it must be something else so we need to be kind of 100 % sure of what we are saying to prove this is due to the time changes/time zone. That said, it is extremely contradictory the OS post this randomly, if you have a post that happens when the time/timezone change you would expect this will only happen when this event occurs in the system and not randomly. – Luciano Perez Jan 19 '22 at 20:50
  • But that isn't how event driven programming works. I mean, with iOS this sort of issue arises all the time: you are surprised by when you get an event. It isn't what you expected. But the system cares nothing about your surprise or expectations. It's up to you to work out what is happening and cope. You have to code defensively. – matt Jan 20 '22 at 03:14
  • Also there's many a slip. I once added the same object as a notification observer twice. Boy was I confused when I got two notifications every time. And debugging that sort of mistake is very difficult. So don't rule out the possibility of your own fallibility. – matt Jan 20 '22 at 03:16
  • @matt yes, it seems to be like this. Look at the answer I got from the Apple support team that I appended to the original post. – Luciano Perez Jan 20 '22 at 10:04
  • Yup. That is exactly what I told you. – matt Jan 20 '22 at 11:03

0 Answers0