Existe uma maneira de verificar se o dispositivo iOS está bloqueado / desbloqueado?
Eu usei atualizações de localização por GPS no meu aplicativo. Quero detectar se o dispositivo iOS está no modo de suspensão para que eu possa desativar as atualizações de localização GPS e otimizar o uso da bateria. Eu já tentei pausarLocationupdates no iOS 6, mas não funciona como desejado. Desejo desligar as atualizações de localização GPS assim que o dispositivo entrar no modo de suspensão. Eu quero detectar o evento de bloqueio / desbloqueio no dispositivo.
Existe alguma maneira de conseguir essa funcionalidade?
até agora eu tenho as notificações darwin como dado abaixo
-(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);
}
Eu sou capaz de obter as notificações darwin quando o dispositivo está bloqueado / desbloqueado, mas o verdadeiro problema é como identificar entre se a notificação veio de bloqueio ou o desbloqueio do dispositivo. Os logs do console são:
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
Qualquer API privada também seria suficiente. Desde já, obrigado.