BatteryState Returning (null)

Discussion in 'iOS Development' started by maxk96, Sep 12, 2010.

  1. maxk96

    maxk96 New Member

    Joined:
    Jul 8, 2009
    Messages:
    37
    Likes Received:
    0
    Device:
    2G iPod touch
    Hi, i have battery state returning null in my app. Please can you say whats wrong?

    [OBJC]
    - (void) checkBattery: (id) sender
    {
    NSArray *stateArray = [NSArray arrayWithObjects: @"Battery state is Unknown", @"Battery is not plugged into a charging source", @"Battery is charging", @"Battery state is full", nil];
    }
    - (void)viewDidLoad {
    [[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];
    [[NSNotificationCenter defaultCenter] addObserver:self selector

    Please Register or Log in to view images

    selector(checkBattery

    Please Register or Log in to view images

    name:UIDeviceBatteryStateDidChangeNotification object:nil];
    [NSTimer scheduledTimerWithTimeInterval:0.1f target:self selector

    Please Register or Log in to view images

    selector(checkBattery

    Please Register or Log in to view images

    userInfo:nil repeats:YES];

    NSArray *stateArray = [NSArray arrayWithObjects:
    @"Battery State Is Unknown",
    @"Battery is Unplugged",
    @"Battery is Charging",
    @"Battery state is full", nil];

    if (cell.textLabel.text == @"Battery State")
    {
    [[cell detailTextLabel] setText: [NSString stringWithFormat

    Please Register or Log in to view images

    "%@", [stateArray objectAtIndex:[[UIDevice currentDevice] batteryState]]]];
    }
    [/OBJC]

Share This Page