title: How to get correct battery level and battery status-ios?
body: <p>Always <code>[myDevice batteryLevel]</code> returning -1 and <code>[myDevice batterystate]</code>returning 0(entering into Default case). </p>
  
  <p>How can i get the correct values?.Can anyone please help me to solve this?.Below is my code.(Always Printing batteryLeft as "-100%" and Battery Status as "Unknown"). </p>
  
  <p><strong>Code:</strong> </p>
  
  <pre><code>UIDevice *myDevice = [UIDevice currentDevice];
  [myDevice setBatteryMonitoringEnabled:YES];
  float batLeft = [myDevice batteryLevel]*100;
  int status=[myDevice batteryState];
  NSLog(@"level:%0.0f",batLeft);
  NSString *status_str;
  switch (status)
  {
      case UIDeviceBatteryStateUnplugged:
      {
          NSLog(@"UnpluggedKey");
          status_str=@"UnPlugged";
          break;
      }
      case UIDeviceBatteryStateCharging:
      {
          NSLog(@"ChargingKey");
          status_str=@"Charging";
          break;
      }
      case UIDeviceBatteryStateFull:
      {
          NSLog(@"FullKey");
          status_str=@"BatteryFul";
          break;
      }
  
  default:
  {
      NSLog(@"UnknownKey");
      status_str=@"Unknown";
      break;
  }
  }
  NSLog(@"Battery status:%@",status_str);
  </code></pre>