[英]How know if iOS device is sleeping in a background process
I have a application running in background and I need to know if device is sleeping in order to start a sincronisation process, but I didn't find information about this. 我有一个在后台运行的应用程序,我需要知道设备是否在睡眠中才能启动刺激程序,但是我没有找到有关此的信息。
Does anyone know if it is posible and how do it? 有谁知道它是否可行以及如何做到?
Thanks. 谢谢。
You cannot know if the device is asleep because you have no control over the OS. 您无法知道设备是否处于睡眠状态,因为您无法控制操作系统。
You can, otherwise, use the App Delegate method: 否则,您可以使用App Delegate方法:
- (void)applicationWillResignActive:(UIApplication *)application
{
//your code goes here
}
if you want to wait till your app goes to background 如果您想等到应用程序进入后台
I believe you can't do this using public API. 我相信您无法使用公共API来执行此操作。 The only thing which you can check whether your application is active or in background (using AppDelegate callbacks).
您可以检查应用程序是处于活动状态还是处于后台状态(使用AppDelegate回调)的唯一操作。 And as Luke pointed out in comments, checking whether device "falls asleep" isn't iOS best design practice.
正如Luke在评论中指出的那样,检查设备是否“入睡”不是iOS的最佳设计实践。
There are some private API's to do what you want, you can look at following questions: 有一些专用的API可以执行您想要的操作,您可以查看以下问题:
Is there a way to check if the iOS device is locked/unlocked? 有没有办法检查iOS设备是否已锁定/未锁定?
Detect screen on/off from iOS service 通过iOS服务检测屏幕的开/关
However, you should be aware that your app won't be accepted in AppStore in such case. 但是,您应该注意,在这种情况下,您的应用程序不会在AppStore中被接受。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.