当我在swift中打开iOS设备上的设备锁定或解锁等通知面板时如何获取事件

时间:2017-12-13 01:16:04

标签: ios swift core-foundation

enter image description here

下图是通知面板。 当我们打开通知面板,设备解锁或解锁以及空白屏幕状态时,我使用了corefoundation框架来获取事件。除了我拖动通知面板之外,我收到了所有事件。如何获取通知面板的事件。

以下代码我习惯了事件

CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), nil, {
    (center, observer, name, object, userInfo) -> Void in
        let lockState = name
        print("lock state : \(String(describing: lockState))")
        print("DEVICE STATE CHANGED")

        if  AppConstants.sharedInstance.isDeviceLocked == true {
            print("DEVICE IS LOCKED")
        }
        else {
            print("DEVICE IS UNLOCKED")
            AppConstants.sharedInstance.isDeviceLocked = false
        }
    }, "com.apple.springboard.lockstate" as CFString, nil, CFNotificationSuspensionBehavior.deliverImmediately)

0 个答案:

没有答案