gpt4 book ai didi

ios - 有没有办法检查 iOS 设备是否已锁定/解锁?

转载 作者:技术小花猫 更新时间:2023-10-29 10:30:17 26 4
gpt4 key购买 nike

我在我的应用程序中使用了 GPS 位置更新。我想检测 iOS 设备是否处于 sleep 模式,以便我可以关闭 GPS 位置更新并优化电池使用。我已经在 iOS 6 中尝试过 pausesLocationupdates,但它没有按预期工作。我想在设备进入休眠模式后立即关闭 GPS 位置更新。我想检测设备中的锁定/解锁事件。

有什么办法可以实现这个功能吗?

到目前为止,我收到了下面给出的 Darwin 通知

-(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);


}

当设备锁定/解锁时,我能够收到 Darwin 通知,但真正的问题是如何识别通知是来自设备锁定还是解锁。控制台日志是:

 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

任何私有(private) API 也足够了。提前致谢。

最佳答案

现在不允许应用监听设备锁定通知!

我收到了这个:

Dear developer,

We have discovered one or more issues with your recent submission for "xxxx". To process your submission, the following issues must be corrected:

Unsupported operation - Apps are not allowed to listen to device lock notifications.

Once these issues have been corrected, use Xcode or Application Loader to upload a new binary to iTunes Connect. Choose the new binary on the app’s Details page in My Apps on iTunes Connect, and click Submit for Review.

Regards,

The App Store team
April 26 2017 at 10:56

关于ios - 有没有办法检查 iOS 设备是否已锁定/解锁?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14229955/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com