On Dec 18, 2019, at 12:39 PM, Jean-Daniel <mail...@xenonium.com> wrote:
> 
>> Le 18 déc. 2019 à 20:10, Carl Hoefs via Cocoa-dev <cocoa-dev@lists.apple.com 
>> <mailto:cocoa-dev@lists.apple.com>> a écrit :
>> 
>>> On Dec 18, 2019, at 11:35 AM, James Walker via Cocoa-dev 
>>> <cocoa-dev@lists.apple.com <mailto:cocoa-dev@lists.apple.com>> wrote:
>>> 
>>> On 12/18/19 9:55 AM, Carl Hoefs via Cocoa-dev wrote:
>>> 
>>>> However, I cannot get this notification to fire on system time changes. My 
>>>> other notifications (such as sleep wake, etc) do fire.
>>>> -Carl
>>>>    [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver: self
>>>>            selector: @selector(systemTimeChanged:)
>>>>            name: NSSystemClockDidChangeNotification object: NULL];
>>>> -(void) systemTimeChanged: (NSNotification *) notification
>>>> {
>>>>    NSLog(@"-systemTimeChanged: %@", [notification name]);
>>>> }
>>> 
>>> I'm not sure what that workspace notification center is for.  Maybe try 
>>> [NSNotificationCenter defaultCenter].
>> 
>> 
>> Thanks for the suggestion. Apple docs have [[[NSWorkspace sharedWorkspace] 
>> notificationCenter] in their code snippets. But [NSNotificationCenter 
>> defaultCenter] doesn't work either. Very odd. Might there be some way in 
>> Xcode or Console to see what notifications are being fired?
>> 
> 
> Workspace Notification Center is only for workspace specific notifications. 
> All other notifications are send on the default Notification Center only.
> 
> I just did test, and I properly receive notifications on each time change in 
> the System preferences.

Argh, I ran my test incorrectly... I just now verified that using 
[NSNotificationCenter defaultCenter] works for both 
NSSystemClockDidChangeNotification and NSSystemTimeZoneDidChangeNotification, 
as it should. 

But Workspace notifications, like NSWorkspaceWillSleepNotification and 
NSWorkspaceDidWakeNotification require [[NSWorkspace sharedWorkspace] 
notificationCenter]. Makes sense.


> On Dec 18, 2019, at 2:18 PM, Jens Alfke <j...@mooseyard.com> wrote:
> 
> If you add an observer with a notification name and object of nil, it will 
> receive all notifications sent to that center.

That's very handy to know!

Thanks to all!
-Carl

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to