Есть ли способ проверить, заблокировано ли устройство iOS?
Я использовал обновления местоположения GPS в моем приложении. Я хочу определить, находится ли устройство iOS в спящем режиме, чтобы можно было отключить обновления местоположения GPS и оптимизировать использование батареи. Я уже пробовал pausesLocationupdates в iOS 6, но он не работает должным образом. Я хочу отключить обновления местоположения GPS, как только устройство перейдет в спящий режим. Я хочу обнаружить событие блокировки / разблокировки в устройстве.
Есть ли способ достичь этой функциональности?
до сих пор я получил уведомления Дарвина, как указано ниже
-(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);
}
Я могу получить уведомления Дарвина, когда устройство заблокировано / разблокировано, но реальная проблема заключается в том, как определить, пришло ли уведомление о блокировке или разблокировке устройства. Консольные журналы:
LockDetectDemo[2086] : IN Display status changed
LockDetectDemo[2086] : Darwin notification NAME = com.apple.springboard.lockcomplete
LockDetectDemo[2086] : IN Display status changed
LockDetectDemo[2086] : Darwin notification NAME = com.apple.springboard.lockstate
LockDetectDemo[2086] : IN Display status changed
LockDetectDemo[2086] : Darwin notification NAME = com.apple.springboard.hasBlankedScreen
LockDetectDemo[2086] : IN Display status changed
LockDetectDemo[2086] : Darwin notification NAME = com.apple.iokit.hid.displayStatus
Любого частного API также будет достаточно. Заранее спасибо.