iOS - Programatically get battery usages of an application
Asked Answered
V

1

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.

Vichy answered 13/5, 2015 at 8:40 Comment(2)
possible duplicate of iPhone4 iOS5 battery level monitoring do I need to add setBatteryMonitoringEnabled:NO to periodic battery checks?Higgins
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.Vichy
B
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

Bos answered 13/5, 2015 at 10:21 Comment(3)
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.Vichy
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.Vichy
@SantoshKumar Did you find answer to your query. I am also looking for something that can give me the battery usage for my applicationThurmond

© 2022 - 2024 — McMap. All rights reserved.