Battery Usage - IOS

2019-04-01 19:24发布

I want to show battery usage of the app on the status bar of the app. It uses GPS, so GPS signal and details of battery usage by app would be useful for the users about the battery drain.

Is there a way to get the battery usage from the device? and to show only the amount of battery drained by my app alone. On instruments it shows the graph over the time.

I want to show battery usage in numerical format, not a graph.

2条回答
我只想做你的唯一
2楼-- · 2019-04-01 19:50

From command line we can get the battery details of iOS phones using libimobiledevice tools.

Inside the tools use the command:

./ideviceinfo -q com.apple.mobile.battery

It will return something like:

BatteryCurrentCapacity: 30 BatteryIsCharging: true ExternalChargeCapable: true ExternalConnected: true FullyCharged: false GasGaugeCapability: true

查看更多
走好不送
3楼-- · 2019-04-01 20:06

Use below code to get battery level

UIDevice *myDevice = [UIDevice currentDevice];
[myDevice setBatteryMonitoringEnabled:YES];
float batteryLevel = [myDevice batteryLevel];
_battery.text = [NSString stringWithFormat:@"%f",batteryLevel*100];
[myDevice batteryLevel];

will give you the battery between 0.0 (empty) and 1.0 (100% charged)

iOS - Issue with displaying battery status

查看更多
登录 后发表回答