15

I'm an iOS developer coming to the Mac. On iOS, we can implement the applicationSignificantTimeChange: method in our app delegate or register for the UIApplicationSignificantTimeChangeNotification notification to react to changes in the system time.

I cannot seem to find an equivalent on the Mac. How can I observe significant changes in the system time (examples: user changes time (zone), switch from/to daylight savings) in macOS (other than starting a timer that fires every second or so)?

ricardopereira
  • 10,295
  • 5
  • 60
  • 72
Ole Begemann
  • 134,064
  • 30
  • 273
  • 252
  • 2
    possible duplicate of [How can I get notified of a system time change in my Cocoa application?](http://stackoverflow.com/questions/690326/how-can-i-get-notified-of-a-system-time-change-in-my-cocoa-application) – jtbandes Sep 18 '15 at 02:47

1 Answers1

2

You need to track NSCurrentLocaleDidChangeNotification, NSSystemClockDidChangeNotification, NSSystemTimeZoneDidChangeNotification and NSWorkspaceDidWakeNotification and then re-schedule timers for all significant timestamps such as midnight.

Mac Catalyst does support UIApplicationSignificantTimeChangeNotification.

Kentzo
  • 3,773
  • 28
  • 48