iPhone4如何查看电源线是否已插入? [英] iPhone4 how to find out if the power cable is plugged in?

查看:154
本文介绍了iPhone4如何查看电源线是否已插入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道我的应用程序是否在连接外部电源线的情况下运行。是否有可能在运行时找到这种状态?

I would like to know if my app is running with an external power cable attached. Is it possible to find out this state at runtime?

一个额外的问题:这是否可以区分真正的USB电源和那些外部电池组?

An extra question: would this be able to differentiate between true USB power and those external "battery packs"?

谢谢!

推荐答案

使用 UIDevice property batteryState

Use UIDevice property batteryState:

[[UIDevice currentDevice] batteryState] == UIDeviceBatteryStateCharging

来自 UIDevice Docs

typedef enum {
    UIDeviceBatteryStateUnknown,
    UIDeviceBatteryStateUnplugged,
    UIDeviceBatteryStateCharging,
    UIDeviceBatteryStateFull,
} UIDeviceBatteryState;

至于你的第二个问题。我不相信你可以确定电池组和壁式充电器之间的任何区别,因为上面的 UIDeviceBatteryState 标志是设备电池可以报告的唯一状态。因此,电池组和壁式充电器都会显示为 UIDeviceBatteryStateCharging UIDeviceBatteryStateFull (或 UIDeviceBatteryStateUnplugged 如果电池组已经插上电池但是没电了。)

As for your 2nd question. I don't believe you can determine any difference between a battery pack and a wall charger since the above UIDeviceBatteryState flags are the only "states" a device battery can report. So both a battery pack and wall charger would appear as either UIDeviceBatteryStateCharging or UIDeviceBatteryStateFull (or UIDeviceBatteryStateUnplugged if the battery pack is plugged in but out of juice).

这篇关于iPhone4如何查看电源线是否已插入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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