【问题标题】:Does Snow Leopard/Lion supports kEventSystemTimeDateChangedSnow Leopard/Lion 是否支持 kEventSystemTimeDateChanged
【发布时间】: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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-09
    • 1970-01-01
    相关资源
    最近更新 更多