What event is fired when Mac is back from sleep?

前端 未结 3 1834
逝去的感伤
逝去的感伤 2020-12-31 09:41

I am developing an app in Xcode on Mac and would like to know the event which is fired when the mac gets back from sleep. AwakeFromNib doesn\'t seem to work.

Thanks

3条回答
  •  梦毁少年i
    2020-12-31 10:08

    Just found it:

    - (void) receiveWakeNote: (NSNotification*) note
    {
        NSLog(@"receiveSleepNote: %@", [note name]);
    }
    
    - (void) fileNotifications
    {
        //These notifications are filed on NSWorkspace's notification center, not the default 
        // notification center. You will not receive sleep/wake notifications if you file 
        //with the default notification center.
         [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver: self 
                                                               selector: @selector(receiveWakeNote:) 
                                                                   name: NSWorkspaceDidWakeNotification object: NULL];
    }
    

提交回复
热议问题