¿Hay alguna forma de verificar si el dispositivo iOS está bloqueado / desbloqueado?
He utilizado actualizaciones de ubicación GPS en mi aplicación. Quiero detectar si el dispositivo iOS está en modo de suspensión para poder desactivar las actualizaciones de ubicación GPS y optimizar el uso de la batería. Ya he intentado pausesLocationupdates en iOS 6, pero no funciona como se desea. Quiero desactivar las actualizaciones de ubicación GPS tan pronto como el dispositivo pase al modo de suspensión. Quiero detectar el evento de bloqueo / desbloqueo en el dispositivo.
¿Hay alguna manera de lograr esta funcionalidad?
Hasta ahora he recibido las notificaciones de Darwin como se indica a continuación
-(void)registerForall
{
//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);
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), //center
NULL, // observer
displayStatusChanged, // callback
CFSTR("com.apple.springboard.lockcomplete"), // event name
NULL, // object
CFNotificationSuspensionBehaviorDeliverImmediately);
}
//call back
static void displayStatusChanged(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo)
{
NSLog(@"IN Display status changed");
NSLog(@"Darwin notification NAME = %@",name);
}
Puedo recibir las notificaciones de Darwin cuando el dispositivo está bloqueado / desbloqueado, pero el problema real es cómo identificar si la notificación proviene del bloqueo o el desbloqueo del dispositivo. Los registros de la consola son:
LockDetectDemo[2086] <Warning>: IN Display status changed
LockDetectDemo[2086] <Warning>: Darwin notification NAME = com.apple.springboard.lockcomplete
LockDetectDemo[2086] <Warning>: IN Display status changed
LockDetectDemo[2086] <Warning>: Darwin notification NAME = com.apple.springboard.lockstate
LockDetectDemo[2086] <Warning>: IN Display status changed
LockDetectDemo[2086] <Warning>: Darwin notification NAME = com.apple.springboard.hasBlankedScreen
LockDetectDemo[2086] <Warning>: IN Display status changed
LockDetectDemo[2086] <Warning>: Darwin notification NAME = com.apple.iokit.hid.displayStatus
Cualquier API privada también sería suficiente. Gracias por adelantado.