Does anybody know if there is an xcode unlock event that can track if somebody unlocks his iPhone?
Or is this only possible with jailbroken devices?
Thanks in advance.
Yes you can do this on a non-jailbroken device using CFNotificationCenterAddObserver
.
Add an observer for the Darwin notification 'lockstate':
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),
NULL,
lockStateDidNotify,
CFSTR("com.apple.springboard.lockstate"),
NULL,
CFNotificationSuspensionBehaviorDeliverImmediately);
and you will be notified each time the device locks/unlocks:
static void lockStateDidNotify(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo)
{
NSLog(@"The Device Locked/Unlocked");
}
Since this fires for both a lock and an unlock it is not entirely what you want, but you can observe com.apple.springboard.lockcomplete
(which only fires during a lock) and check to see if you get both. If you don't get the lockcomplete
you can assume an unlock just happened.