-2

Possible Duplicate:
time remaining until charge is complete,iOS

I am using below code to get the battery level

UIDevice *myDevice = [UIDevice currentDevice];
[myDevice setBatteryMonitoringEnabled:YES];
float batLeft = [myDevice batteryLevel];
int i=[myDevice batteryState];

batinfo=(batLeft*100);

But i am not able to figure out, how to calculate/estimate the time remaining in full charge , i.e when battery level = 100%.

I m trying to get something like time remaining full charge = 01:30:10

Suggestions is always appreciated.

Thanks

Community
  • 1
  • 1
Shishir.bobby
  • 10,994
  • 21
  • 71
  • 100

1 Answers1

1

An example of battery specs on Apple's site, you would probably need to record all the devices and use conditions to see which one is which:

  • Talk time: Up to 8 hours on 3G, up to 14 hours on 2G (GSM)

  • Standby time: Up to 200 hours

  • Internet use: Up to 6 hours on 3G, up to 9 hours on Wi-Fi

  • Video playback: Up to 10 hours

  • Audio playback: Up to 40 hours

The code to get the percentage of battery left is:

[[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];
float batteryLevel = [myDevice batteryLevel];

Thats all you can do, so anything else an app uses is guesswork and calculations on your half.

Credits -- copied from here, had to do it because you said it is "not what i needed" even though it is the exact answer.

So to conclude it is not possible using the native API, you must setup conditions to find what model the device is and do the calculations by using specs from apple's site.

Community
  • 1
  • 1
MCKapur
  • 9,127
  • 9
  • 58
  • 101
  • Thanks rohan...but i already used it.this done give the result which i m expecting – Shishir.bobby Jan 12 '13 at 12:59
  • @iscavengers **Read the full answer** not just the code – MCKapur Jan 12 '13 at 13:02
  • @iscavengers I basically say find out the specs of each device your app can run on and use conditions to find the current model of the device and then calculate the avg. battery life time – MCKapur Jan 12 '13 at 13:08
  • That i already did rohan...the only thing where i got stuck is how to estimate the charge time remaining untill its fully charge. – Shishir.bobby Jan 12 '13 at 13:17