Getting Battery Info - 3.0

Discussion in 'iOS Programming' started by Jeremy1026, Mar 25, 2009.

  1. Jeremy1026 macrumors 68020

    Jeremy1026

    Joined:
    Nov 3, 2007
    #1
    I am trying to return the battery level of the device. But, no matter what my battery is, it returns 1.0. Here is my code that I am using.


    Code:
    UIDevice *myDevice = [UIDevice currentDevice];
    
    [myDevice setBatteryMonitoringEnabled:YES];
    float batLeft = [myDevice batteryLevel]; 
    
    NSLog(@"%f",batLeft);
     
  2. Jeremy1026 thread starter macrumors 68020

    Jeremy1026

    Joined:
    Nov 3, 2007
    #2
    Solved: This code does work. I just wasn't letting my battery drain enough. It only updates every 5% (from what I can tell.)
     
  3. mexicanrooster macrumors newbie

    Joined:
    Jun 19, 2009
    #3
    I am trying to read the battery using 2.2.1 but it fails. Is it only supported by 3.0?

    Thx.
     
  4. Jeremy1026 thread starter macrumors 68020

    Jeremy1026

    Joined:
    Nov 3, 2007
    #4
    Yes, 3.0 only.
     

Share This Page