How to get battery consumption value for an iOS app (x mAh/min)?
Asked Answered
B

4

9

I'm currently trying to improve the battery usage of the app we're developing.

The only thing I found was percentage with a jailbreak solution (here),

I did not find absolute value like 3.4 mAh/min as example.

I also did not find iOS guidelines to assess the battery consumption.

Ideally, I would love to see is something like that :

  • Google Analytics SDK : 0.4 mAh/min
  • Bluetooth SDK : 1.0 mAh/min
  • API SDK : 2.0 mAh/min

Something as Battery Doctor is providing :

enter image description here

Is that even possible ?

Thank for your help !

Billposter answered 11/9, 2013 at 12:34 Comment(4)
Are you able to do this ?Caledonian
@Caledonian Any success in this?Mastersinger
To be clear: there is no such thing as a mAh/min. That's a totally made up unit of measurement that means nothing. Power consumption would typically be measured as milliamperes (mA), or watts (W).Isentropic
@Isentropic Technically, one could argue that it's equal to mA * h/min = 1/60 of mA. That's a strange measurement for sure thoughPolystyrene
W
4

We have had mixed success using https://github.com/ethan605/ios-battery-stat, which relies on a private API.

So, you cannot use that if you deploy your app on the Apple Store, but it can be useful when deploying to TestFlight or similar beta-user app stores.

Sami

Wreck answered 20/9, 2013 at 16:2 Comment(1)
This github demo just give the battery level and battery state. It doesn't give the battery consumed by apps.Caledonian
Z
1

After doing some tests, over a couple of days, I have a VERY strong suspicion that these numbers we see are NOT actual measurements on the device, they seem WAY too constant, and only some of the actually running apps are on the list...

I have a THEORY that they have some sort of limited database, and if any app on the phone is matching this list, it is included.

It could still be useful as a hint on what uses a lot, and what uses a little. But I do not think you should see it as 'real' numbers from your phone. Can anyone confirm or disprove this theory???

That also explains why you can't find a method to get this info

There are also TWO almost identical apps one with a orange and one with a green battery icon, And it seems to be the same apps that are included and excluded. that seems a bit fishy too... There is a third app "Battery Lite", that are similar but without mAh/min readings (strange unit btw)

Zeena answered 9/1, 2015 at 23:28 Comment(2)
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient reputation you will be able to comment on any post.Torpedo
Even though this does not provide a DEFINITE answer, it does provide a POSSIBLE answer on why we can not find the info we seek.Zeena
I
1

Try UIDeviceListener, it basically steals the entire battery data dictionary from UIDevice without using any private APIs. It exposes tons of information:

{
    AdapterDetails =     {
        Amperage = 1000;
        Description = "usb host";
        FamilyCode = "-536854528";
        PMUConfiguration = 1000;
        Watts = 5;
    };
    AdapterInfo = 16384;
    Amperage = 1000;
    AppleRawCurrentCapacity = 1279;
    AppleRawMaxCapacity = 1275;
    AtCriticalLevel = 0;
    AtWarnLevel = 0;
    BatteryData =     {
        BatterySerialNumber = REDACTED;
        ChemID = 355;
        CycleCount = 524;
        DesignCapacity = 1420;
        Flags = 640;
        FullAvailableCapacity = 1325;
        ManufactureDate = REDACTED;
        MaxCapacity = 1273;
        MfgData = REDACTED;
        QmaxCell0 = 1350;
        StateOfCharge = 100;
        Voltage = 4194;
    };
    BatteryInstalled = 1;
    BatteryKey = "0003-default";
    BootBBCapacity = 52;
    BootCapacityEstimate = 2;
    BootVoltage = 3518;
    CFBundleIdentifier = "com.apple.driver.AppleD1815PMU";
    ChargerConfiguration = 990;
    CurrentCapacity = 1275;
    CycleCount = 524;
    DesignCapacity = 1420;
    ExternalChargeCapable = 1;
    ExternalConnected = 1;
    FullyCharged = 1;
    IOClass = AppleD1815PMUPowerSource;
    IOFunctionParent64000000 = <>;
    IOGeneralInterest = "IOCommand is not serializable";
    IOInterruptControllers =     (
        IOInterruptController34000000,
        IOInterruptController34000000,
        IOInterruptController34000000,
        IOInterruptController34000000
    );
    IOInterruptSpecifiers =     (
        <03000000>,
        <26000000>,
        <04000000>,
        <24000000>
    );
    IOMatchCategory = AppleD1815PMUPowerSource;
    IOPowerManagement =     {
        CurrentPowerState = 2;
        DevicePowerState = 2;
        MaxPowerState = 2;
    };
    IOProbeScore = 0;
    IOProviderClass = AppleD1815PMU;
    InstantAmperage = 0;
    IsCharging = 0;
    Location = 0;
    Manufacturer = A;
    MaxCapacity = 1275;
    Model = "0003-A";
    Serial = REDACTED;
    Temperature = 2590;
    TimeRemaining = 0;
    UpdateTime = 1461830702;
    Voltage = 4182;
    "battery-data" =     {
        "0003-default" = <...>;
        "0004-default" = <...>;
        "0005-default" = <...};
    "built-in" = 1;
}

Of special interest is the InstantAmperage key, which (while the device is unplugged) shows actual device power consumption in mAh. While your app is running, that will show you exact power consumption for your app.

UPDATE: Based on the iOS 10 beta, it looks like Apple has completely removed this information from the dictionary (regardless of how it is loaded, even if we directly load it by calling IOKit). The dictionary still exists, but it now contains only basic keys such as ExternalConnected and CurrentCapacity.

Isentropic answered 30/4, 2016 at 0:34 Comment(0)
P
0

Instruments won't give you a pretty picture like this but it will show you CPU, GPU usage which should generally be an indicator of battery drain and is certainly an good way to look at your application's performance/hardware utilization.

Psilomelane answered 17/9, 2013 at 22:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.