How to measure battery consumption for your application?

I am running my application in background mode. I am interested in measuring the battery consuption in percentage.

In Settings->Battery, it shows Screen On and Off time for the application. For battery consumption percentage of the application, the data 'Connected to Charger' is shown when actually it s not connected.

Replies

See https://developer.apple.com/documentation/uikit/uidevice/1620042-batterylevel - as noted there "Before accessing this property, ensure that battery monitoring is enabled."


If you've done that, show some code, pls.