途径: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)
}