开发者

How to detect from an iPhone app whether the battery is in charging or not?

In m开发者_StackOverflow中文版y iPhone app, there is a requirement to know whether the iPhone is charging or not?

If it is charging then I want to display alert for the same.

So how can I detect whether the iPhone is charging or not?


[[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];

if ([[UIDevice currentDevice] batteryState] != UIDeviceBatteryStateUnplugged) {
    //Device is connected (charging or fully charged)
}

Edit: If you relly want to check if the device is charging (and not 100% full yet), use the UIDeviceBatteryStateCharging constant in the if statement. See the documentation for more information.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜