Gibt es eine Möglichkeit zu überprüfen, ob das iOS-Gerät gesperrt / entsperrt ist?
Ich habe GPS-Standortaktualisierungen in meiner Anwendung verwendet. Ich möchte feststellen, ob sich das iOS-Gerät im Energiesparmodus befindet, damit ich die GPS-Standortaktualisierungen deaktivieren und die Akkunutzung optimieren kann. Ich habe bereits pausesLocationupdates in iOS 6 ausprobiert, aber es funktioniert nicht wie gewünscht. Ich möchte die GPS-Standortaktualisierungen deaktivieren, sobald das Gerät in den Ruhemodus wechselt. Ich möchte das Sperr- / Entsperrereignis im Gerät erkennen.
Gibt es eine Möglichkeit, diese Funktionalität zu erreichen?
Bisher habe ich die Darwin-Benachrichtigungen wie unten angegeben erhalten
-(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);
}
Ich kann die Darwin-Benachrichtigungen abrufen, wenn das Gerät gesperrt / entsperrt ist. Das eigentliche Problem ist jedoch, ob die Benachrichtigung vom Sperren oder Entsperren des Geräts stammt. Konsolenprotokolle sind:
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
Jede private API würde ebenfalls ausreichen. Danke im Voraus.