iPhone에서 화면 잠금 해제 이벤트를 감지하려면 어떻게해야합니까? 사용자가 잠금을 해제하면 내 앱에서 작업을 수행하려고합니다. 내가 검색 좀하지만 객관적인 C와 관련된 코드를 발견, 신속하지만 그 작동하지 않는 것으로 변경했습니다.
이 블로그를 따르십시오 : http://kidtechblogs.blogspot.com/2014/07/how-to-detect-screen-lockunlock-events.html.
어떻게 도와 드릴까요? 우리는 당신이 네이티브 코드를 사용하여 화면 잠금 - 해제 상태를 감지 할 수 없습니다 알고 다음은 지금까지 ..IOS 스위프트에서 화면 잠금 해제 이벤트 감지
func displayStatusChanged(center: CFNotificationCenter, observer: Void, name: CFString, object: Void, userInfo: CFDictionaryRef) {
// the "com.apple.springboard.lockcomplete" notification will always come after the "com.apple.springboard.lockstate" notification
let lockState = (name as String)
print("Darwin notification NAME = \(name)")
if (lockState == "com.apple.springboard.lockcomplete") {
print("DEVICE LOCKED")
}
else {
print("LOCK STATUS CHANGED")
}
}
func registerforDeviceLockNotification() {
//Screen lock notifications
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), //center
nil, // observer
displayStatusChanged, // callback
CFSTR("com.apple.springboard.lockcomplete"), // event name
nil, // object
.deliverImmediately)
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), //center
nil, // observer
displayStatusChanged, // callback
CFSTR("com.apple.springboard.lockstate"), // event name
nil, // object
.deliverImmediately)
}
앱이 포 그라운드 일 때 작동합니까? – OhadM
이 코드는 작동하지 않습니다. – fmashkoor
우선, displayStatusChanged 메소드는 정적 인 것으로 가정합니다. 그것을 확인하십시오. – OhadM