cocoa

Mac 中对系统Sleep 与 Wake 的检测

2015-11-30  本文已影响116人  无影灯

途径:notificationCenter

通过 NSWorkspace的notificationCenter中对相应通知,可知系统现在状态,通过通过相应委托进行处理

    func didReceivedWakeNote(note: NSNotification){
      //code
    }
    
    func didReceivedSleepNote(note: NSNotification){
      //code
    }
    
    func startBluetoothAfterWake(){
        NSWorkspace.sharedWorkspace().notificationCenter.addObserver(self, selector: "didReceivedWakeNote:", name: NSWorkspaceDidWakeNotification, object: nil)
    }
    
    func stopBluetoothBeforeSleep(){
        NSWorkspace.sharedWorkspace().notificationCenter.addObserver(self, selector: "didReceivedSleepNote:", name: NSWorkspaceWillSleepNotification, object: nil)
        
    }
上一篇下一篇

猜你喜欢

热点阅读