简体   繁体   English

如何知道iOS设备是否在后台进程中休眠

[英]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.

相关问题 需要知道如何在Xamarin.iOS中杀死后台进程 - Need to know how to kill background process in Xamarin.iOS 如何知道当应用程序在后台且其在ios系统中首先连接时何时检索连接的ble设备? - How to know when to retrieve connected ble device while app is in background and its connected first in ios system? 如何知道在后台运行的iOS应用程序的蓝牙设备连接/断开状态回调? - How to know the Bluetooth device connection/disconnection status callbacks to an iOS application running in background? 如何知道某个iOS设备在某个附近? - How to know that an iOS device is in a certain vicinity? 如何知道应用程序是秘密安装在ios设备上的? - how to know app was priviously install on ios device? 如何知道iOS设备何时插入? - How to know when iOS device is plugged in? 如何知道iOS中是否连接了蓝牙设备? - How to know if a Bluetooth Device is Connected in iOS? 我们如何知道通知已到达iOS设备? - how we know that notification reached to iOS device? iOS如何在后台重新连接到BLE设备? - iOS how to reconnect to BLE device in background? 如何在iOS设备上测试慢速后台线程 - How to test slow background thread on iOS Device
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM