【发布时间】:2011-09-08 00:08:07
【问题描述】:
我需要在系统首选项面板中进行更改时收到通知。从谷歌文档中我发现 kEventSystemTimeDateChanged 并且它在 Leopard 中工作。但是在雪豹上运行相同的代码 sn-p 时, 时钟更改不会触发事件。我需要澄清 Snow Leopard 和 Lion 是否支持 kEventSystemTimeDateChanged。
我的代码 sn-p 如下所示。
- (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);
}
【问题讨论】:
-
请编辑您的问题以包含您用于注册活动的代码。
-
接下来,您应该删除
(void)演员表并找出InstallApplicationEventHandler返回的状态代码。请编辑您的问题以包含该内容。 -
嗨彼得,我试过这样,状态返回为 0。这是查找状态代码的正确方法吗? OSStatus 状态 = InstallApplicationEventHandler(eventHandlerUPP, 1, &eventType, self, NULL);
-
是的。 0 是
noErr,所以如果这不起作用,你应该提交一个错误:bugreport.apple.com
标签: macos-carbon