美文网首页cocoa
Mac 中对系统Sleep 与 Wake 的检测

Mac 中对系统Sleep 与 Wake 的检测

作者: 无影灯 | 来源:发表于2015-11-30 14:33 被阅读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)
        
    }

相关文章

网友评论

    本文标题:Mac 中对系统Sleep 与 Wake 的检测

    本文链接:https://www.haomeiwen.com/subject/scdjhttx.html