What event is fired when Mac is back from sleep?

前端 未结 3 1837
逝去的感伤
逝去的感伤 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条回答
  •  情歌与酒
    2020-12-31 10:23

    You can use IORegisterForSystemPower().

    Connects the caller to the Root Power Domain IOService for the purpose of receiving sleep & wake notifications for the system. Does not provide system shutdown and restart notifications.

    io_connect_t IORegisterForSystemPower (
        void *refcon, 
        IONotificationPortRef *thePortRef, 
        IOServiceInterestCallback callback, 
        io_object_t *notifier ) ;  
    

    Take a look at Q:How can my application get notified when the computer is going to sleep or waking from sleep? How to I prevent sleep?

提交回复
热议问题