Snow Leopard / Lion是否支持kEventSystemTimeDateChanged

时间:2011-09-07 11:05:13

标签: macos-carbon

我需要在系统首选项面板中进行更改时收到通知。从google文档中我发现了kEventSystemTimeDateChanged并且它在Leopard中工作。但是在雪豹上运行相同的代码片段时, 事件不会因时钟变化而被解雇。我需要澄清Snow Leopard和Lion是否支持kEventSystemTimeDateChanged。

我的代码段如下所示。

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
        [self SystemTimeChangeHandler]; 
}



OSStatus DateChangeEventHandler(EventHandlerCallRef nextHandler, EventRef theEvent, void *userData) 
{
NSLog(@"Event Fired!\n");    
return 0;
}


- (void)SystemTimeChangeHandler
{

NSLog(@"SystemTimeChangeHandler");
EventTypeSpec eventType;

eventType.eventClass = kEventClassSystem;

eventType.eventKind = kEventSystemTimeDateChanged;


EventHandlerUPP eventHandlerUPP =
NewEventHandlerUPP(DateChangeEventHandler);

EventHandlerRef eventHandlerRef = NULL;

(void)InstallApplicationEventHandler(
                                     eventHandlerUPP,
                                     1,
                                     &eventType,
                                     self,
                                     &eventHandlerRef);
}

1 个答案:

答案 0 :(得分:1)

作为解决方法,在Mac OS X 10.6或更高版本中,您可以注册NSSystemClockDidChangeNotification。该文档未明确这是在默认的本地通知中心还是默认的分布式通知中心。