I want to detect the lock/unlock events in the device, so far I got the darwin notifications as given below,:
-(void)registerForDarwinNotif
{
//Screen lock notifications
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), //center
NULL, // observer
displayStatusChanged, // callback
CFSTR("com.apple.iokit.hid.displayStatus"), // event name
NULL, // object
CFNotificationSuspensionBehaviorDeliverImmediately);
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), //center
NULL, // observer
displayStatusChanged, // callback
CFSTR("com.apple.springboard.lockstate"), // event name
NULL, // object
CFNotificationSuspensionBehaviorDeliverImmediately);
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), //center
NULL, // observer
displayStatusChanged, // callback
CFSTR("com.apple.springboard.hasBlankedScreen"), // event name
NULL, // object
CFNotificationSuspensionBehaviorDeliverImmediately);
}
//My call back
static void displayStatusChanged(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo)
{
NSLog(@"IN Display status changed");
// you might try inspecting the `userInfo` dictionary, to see
// if it contains any useful info
NSLog(@"Darwin notification NAME = %@",name);
}
I am able to get the darwin notifications when device is locked/unlocked, but the real problem is how identify between if the notification has come from locking or the unlocking of the device. Console logs are:
Jan 10 11:29:01 Frost-bank LockDetectDemo[2086]
Jan 10 11:29:01 Frost-bank LockDetectDemo[2086]
Jan 10 11:29:01 Frost-bank LockDetectDemo[2086]
Jan 10 11:29:01 Frost-bank LockDetectDemo[2086]
Jan 10 11:29:01 Frost-bank LockDetectDemo[2086]
Jan 10 11:29:01 Frost-bank LockDetectDemo[2086]
Jan 10 11:29:01 Frost-bank LockDetectDemo[2086]
Jan 10 11:29:01 Frost-bank LockDetectDemo[2086]
0 comments:
Post a Comment