下图是通知面板。 当我们打开通知面板,设备解锁或解锁以及空白屏幕状态时,我使用了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)