-3

I want to get the battery usage data from code. How can I do that?

Data what I want to get

gaaamii
  • 5
  • 3

1 Answers1

0

Code will be look like below

[[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;

Resource Link:

iOS: how to get correctly battery level

Community
  • 1
  • 1
SkyWalker
  • 28,384
  • 14
  • 74
  • 132
  • Thanks. But I want to get time that I spend for the specific app. For example: Safari: 2.7 hours on screen 56% Instagram: 29 min on screen 10% – gaaamii Jun 20 '16 at 09:59