iOS:如何从代码中获取电池使用量?

时间:2016-06-19 07:44:39

标签: ios

我想从代码中获取电池使用数据。 我怎么能这样做?

Data what I want to get

1 个答案:

答案 0 :(得分:0)

代码如下所示

[[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];
float batteryLevel = [[UIDevice currentDevice] batteryLevel];

//This will give you the battery between 0.0 (empty) and 1.0 (100% charged)
//If you want it as a percentage, you can do this:

batteryLevel *= 100;

资源链接:

iOS: how to get correctly battery level