iOS - 以编程方式获取应用程序的电池使用情况

San*_*mar 5 battery consumption ios

我想以编程方式获取应用程序的电池使用情况.iOS 8提供电池使用监视器实用程序,我想知道Apple如何实现此功能.这有什么公共API吗?

我希望我的iOS应用程序的电池消耗值为x mAh/min或当前电池状态的x%或任何类似格式.

请帮助.

use*_*143 4

如果您按照以下代码操作就可以

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

另外还有一些针对您问题的链接 - How to get real time Battery Level on iOS with a 1%粒度

  • 这给出了设备的电池电量,但我需要源代码来了解特定应用程序消耗多少电池。支持我的 iPhone 运行 10 个不同的应用程序,然后我想记录每个应用程序的电池消耗值。 (5认同)