您好,欢迎来到化拓教育网。
搜索
您的当前位置:首页Mac 中对系统Sleep 与 Wake 的检测

Mac 中对系统Sleep 与 Wake 的检测

来源:化拓教育网

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

Copyright © 2019- huatuo9.cn 版权所有 赣ICP备2023008801号-1

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务