How can I get notified of a system time change in my Cocoa application?

后端 未结 4 1958
一向
一向 2021-01-04 10:49

I have a Cocoa application that records datestamps on events. I need to know when the system time is reset and by how much, but I can\'t seem to fine a notification anywhere

4条回答
  •  耶瑟儿~
    2021-01-04 11:21

    If some on is looking for solution know system date change change event from 10.4


    OSStatus DateChangeEventHandler(EventHandlerCallRef nextHandler, EventRef theEvent, void *userData) 
    {
        NSLog(@"Event received!\n");    
        return 0;
    }
    
    
    - (void)SystemTimeChangeHandler
    {
        EventTypeSpec eventType;
        eventType.eventClass = kEventClassSystem;
        eventType.eventKind = kEventSystemTimeDateChanged;
    
        EventHandlerUPP eventHandlerUPP =
        NewEventHandlerUPP(DateChangeEventHandler);
        EventHandlerRef eventHandlerRef = NULL;
        (void)InstallApplicationEventHandler(
                                             eventHandlerUPP,
                                             1,
                                             &eventType,
                                             self,
                                             &eventHandlerRef);
    
    }
    

提交回复
热议问题