How to obtain extensive battery info in iOS?
Asked Answered
E

5

5

I'm wondering is it possible to receive information about battery like: capacity (mA), voltage (V), cycle count within iOS?

I know UIDevice class, but battery level is not what I'm looking for.

Elias answered 10/9, 2012 at 6:16 Comment(0)
F
3

I might be wrong about this but using public APIs this is not possible. According to the UIDevice documentation, it appears the most you can do is get the battery charge level, its state, and enable battery monitoring.

Update 15th Feb 2019: Looks like iOS UIDevice API's now allow developers to get access to battery charge level for the device. Whooo! It currently exposes 4 different API's. By the looks of it these are not "private", in other words can be used safely by developers without Apple blocking your app from AppStore.

Getting the Device Battery State

  1. var batteryLevel: Float (The battery charge level for the device).
  2. var isBatteryMonitoringEnabled: Bool (A Boolean value indicating whether battery monitoring is enabled (true) or not (false)).
  3. var batteryState: UIDevice.BatteryState (The battery state for the device).
  4. enum UIDevice.BatteryState (The battery power state of the device).
Frondescence answered 10/9, 2012 at 6:54 Comment(2)
its possible. please check this link - itunes.apple.com/us/app/system-monitor-ultimate/…Fractional
@Wilson its a very old answer. Please feel free to update/edit my answer.Frondescence
P
5

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;
}
Provided answered 30/4, 2016 at 0:4 Comment(1)
Appears this information is no longer there in iOS 10 :-(Haigh
F
3

I might be wrong about this but using public APIs this is not possible. According to the UIDevice documentation, it appears the most you can do is get the battery charge level, its state, and enable battery monitoring.

Update 15th Feb 2019: Looks like iOS UIDevice API's now allow developers to get access to battery charge level for the device. Whooo! It currently exposes 4 different API's. By the looks of it these are not "private", in other words can be used safely by developers without Apple blocking your app from AppStore.

Getting the Device Battery State

  1. var batteryLevel: Float (The battery charge level for the device).
  2. var isBatteryMonitoringEnabled: Bool (A Boolean value indicating whether battery monitoring is enabled (true) or not (false)).
  3. var batteryState: UIDevice.BatteryState (The battery state for the device).
  4. enum UIDevice.BatteryState (The battery power state of the device).
Frondescence answered 10/9, 2012 at 6:54 Comment(2)
its possible. please check this link - itunes.apple.com/us/app/system-monitor-ultimate/…Fractional
@Wilson its a very old answer. Please feel free to update/edit my answer.Frondescence
W
1

Yes it is possible..by using private framework iosDiagnosticsupport.Framework.
After doing some tests, i have certain data about battery rather overall logs for iDevice. Here are some links that might help you... iOS Diagnostics Part 3

Wreath answered 23/6, 2015 at 9:33 Comment(2)
Could you please elaborate more your answer adding a little more description about the solution you provide?Uprear
Actually there is private framework through which you can access device logs... you can go through this project to start withWreath
F
1

Its possible to fetch Battery capacity and voltage using public API and which allowed in app store as well. Here is the link -

  1. app store :https://itunes.apple.com/us/app/system-monitor-ultimate/id740765454?mt=8
  2. github : https://github.com/Asido/SystemMonitorenter image description here
Fractional answered 11/12, 2015 at 22:52 Comment(3)
It's not fetching voltage or capacity from the device, but it reads from pre-filled file: github.com/Asido/SystemMonitor/blob/master/SystemMonitor/…Elias
can you please try with this library. you need to create build to use this. github.com/libimobiledevice/libimobiledeviceFractional
the lib system monitor grabs values from hard coded file.Mews
H
1

Look at the JSystemInfoKit library.

You want to import the IOKit framework first (get the .framework file from here /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/IOKit.framework ) and IOKit headers (get those files from here) in your iOS project.

Here you can find the methods you need to use to get extensive battery information.

Plus, IOPSCopyPowerSourcesInfo (from IOPowerSources.h) returns a NSDictionary with more information like battery health.

Harpsichord answered 2/4, 2016 at 18:39 Comment(4)
It stays that JSystemInfoKit supports OS X only, could you provide more details on iOS implementation?Elias
@WojciechRutkowski I've create a small project on Github github.com/gderaco/iOS-Battery-Info-DemoHarpsichord
@WojciechRutkowski Do you have documentation/tutorial there on his github page and source code of SystemInfoKit? The user has deleted everything.Vexation
@Vexation sorry, I don't have it.Elias

© 2022 - 2024 — McMap. All rights reserved.