6

I want to get battery usages of an application programmatically. iOS 8 provide battery usages monitor utility and I want to know how did Apple implemented this feature. Is there any public API for this ?

I want battery consumption value for my iOS app in x mAh/min or x% of current battery status or any similar format.

Kindly help.

Santosh Kumar
  • 71
  • 1
  • 6
  • possible duplicate of [iPhone4 iOS5 battery level monitoring do I need to add setBatteryMonitoringEnabled:NO to periodic battery checks?](http://stackoverflow.com/questions/8060905/iphone4-ios5-battery-level-monitoring-do-i-need-to-add-setbatterymonitoringenabl) – Nirav Gadhiya May 13 '15 at 08:45
  • Thanks for your quick reply but your reference link does not answer my question. It is telling device battery status but my question is how much battery an application is consuming at any point of time. I want to print the current battery usages of my app then how can I do it. – Santosh Kumar May 13 '15 at 08:52

1 Answers1

4

You can do if you follow the below code

 if (![[UIDevice currentDevice] isBatteryMonitoringEnabled])
 {
   [[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];
 }
 NSLog(@"battery : %f", [[UIDevice currentDevice] batteryLevel]);

Also there is some link for your question - How to get real time battery level on iOS with a 1% granularity

Community
  • 1
  • 1
user3182143
  • 9,459
  • 3
  • 32
  • 39
  • 5
    This gives battery level of device but I need source code for how much battery a particular application consuming. Support my iPhone is running 10 different application then I want to log battery consumption value for each app. – Santosh Kumar May 13 '15 at 10:46
  • 1
    Can you please refer the section in the above link which explain my question exactly. I did not find any answer relevant to my question. All answer post give battery level for device but I want battery consumption rate by my particular iOS app at any point of time. – Santosh Kumar May 13 '15 at 11:09
  • @SantoshKumar Did you find answer to your query. I am also looking for something that can give me the battery usage for my application – labyrinth Jul 13 '17 at 07:54