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
  • 11,118
  • 5
  • 63
  • 81
Ole Begemann
  • 135,006
  • 31
  • 278
  • 256
  • 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

4

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,881
  • 29
  • 54