检测设备是否正在充电 [英] Detect if device is charging

查看:92
本文介绍了检测设备是否正在充电的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使用我最喜欢的工具找到任何明确的信息,但我想我会把它放在这里。 ..

I can't find anything definite using my favourite tool, however I thought I would put it out here...

有没有办法,使用iPhone SDK,一个应用程序检测设备是否处于接收电源状态(充电,停靠等) ?

Is there a way, using the iPhone SDK, for an app to detect if the device is in a state of receiving power (charging, dock, etc.)?

我希望能够在设备接通电源时自动禁用idleTimer(否则它是用户指定的设置)。

I would like to be able to disable the idleTimer automatically if the device is receiving power (otherwise it is a user-specified setting).

推荐答案

是的,UIDevice能够告诉你:

Yes, UIDevice is capable of telling you this:

[[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];

if ([[UIDevice currentDevice] batteryState] == UIDeviceBatteryStateCharging) {
    NSLog(@"Device is charging.");
}

参见 UIDevice 参考文档中的更多信息以及其他值的batteryState。

See the UIDevice reference in the docs for more info, and for other values of batteryState.

这篇关于检测设备是否正在充电的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆