Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 18, 2013, 06:32 PM   #1
xArtx
macrumors 6502a
 
Join Date: Mar 2012
Battery Level low resolution?

Hi Guys,
I have just got battery monitoring working for the first time.
Am I the only one who's seeing the level go down in increments of 5% ?
I might think this is normal, and we just didn't get the same tool Apple uses,
but also, when plugged into a power source, I don't see a negative number,
just the battery level.

So it's 100%, 95%, 80%, 75%, and so on....
Thanks, Art.
xArtx is offline   0 Reply With Quote
Old Feb 18, 2013, 06:47 PM   #2
ArtOfWarfare
macrumors 601
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
That sounds right. I think iOS takes that number and combines it with data about how long the screen has been on an how long it's been plugged in to display the 1% increment it shows the user. I know I've seen my iPhone shut off moments after it said it was at 5% more than once.
ArtOfWarfare is offline   0 Reply With Quote
Old Feb 18, 2013, 07:14 PM   #3
xArtx
Thread Starter
macrumors 6502a
 
Join Date: Mar 2012
Quote:
Originally Posted by ArtOfWarfare View Post
That sounds right. I think iOS takes that number and combines it with data about how long the screen has been on an how long it's been plugged in to display the 1% increment it shows the user. I know I've seen my iPhone shut off moments after it said it was at 5% more than once.
That's ok, as long as I'm not seeing something different from everyone else.
How do you detect it's plugged in? I've never seen a negative number in the
battery level value.
xArtx is offline   0 Reply With Quote
Old Feb 20, 2013, 12:21 PM   #4
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
Quote:
Originally Posted by xArtx View Post
How do you detect it's plugged in?
Have you looked into UIDeviceBatteryState yet?
__________________
dejo is offline   0 Reply With Quote
Old Feb 20, 2013, 02:27 PM   #5
Duncan C
macrumors 6502a
 
Duncan C's Avatar
 
Join Date: Jan 2008
Location: Northern Virginia
 
see vendor information in user profile
Quote:
Originally Posted by ArtOfWarfare View Post
That sounds right. I think iOS takes that number and combines it with data about how long the screen has been on an how long it's been plugged in to display the 1% increment it shows the user. I know I've seen my iPhone shut off moments after it said it was at 5% more than once.
iOS devices use lithium ion batteries. You can't measure the remaining charge with lithium batteries like you can with other batteries. They hum along putting out full power, then suddenly stop without warning. Instead, lithium batteries have chips in them that track usage, battery age, etc, and use those factors to estimate remaining battery power. The estimate is just that, an estimate. As the battery ages, the estimate gets less accurate.

It might be that Apple is using other factors to estimate remaining battery, but it might also be that they use a completely different private API. My money is on the private API.
__________________
Regards,
Duncan Champney, WareTo.
Check out our latest iOS app, Face Dancer, available for free on the App Store.
Duncan C is offline   0 Reply With Quote
Old Feb 20, 2013, 05:12 PM   #6
xArtx
Thread Starter
macrumors 6502a
 
Join Date: Mar 2012
Quote:
Originally Posted by Duncan C View Post
It might be that Apple is using other factors to estimate remaining battery, but it might also be that they use a completely different private API. My money is on the private API.
It's all ok how they are doing it, but private API or not, isn't it odd that they
are creating the potential for an App to say one thing, and the springboard
to say another? Whatever they are doing, they could share that value with us.

Quote:
Have you looked into UIDeviceBatteryState yet?
No, didn't get to reading into it.. but the tutorial did say you get a negative
value if the device is plugged in. I still haven't seen that.
Thanks though, I'll want to know the charging state.
xArtx is offline   0 Reply With Quote
Old Feb 20, 2013, 06:54 PM   #7
Duncan C
macrumors 6502a
 
Duncan C's Avatar
 
Join Date: Jan 2008
Location: Northern Virginia
 
see vendor information in user profile
Quote:
Originally Posted by xArtx View Post
It's all ok how they are doing it, but private API or not, isn't it odd that they
are creating the potential for an App to say one thing, and the springboard
to say another? Whatever they are doing, they could share that value with us.



No, didn't get to reading into it.. but the tutorial did say you get a negative
value if the device is plugged in. I still haven't seen that.
Thanks though, I'll want to know the charging state.
Don't trust third party tutorials without verifying what they say. A quick look at the docs for the UIDevice method batteryLevel reveals the following:


Battery level ranges from 0.0 (fully discharged) to 1.0 (100% charged). Before accessing this property, ensure that battery monitoring is enabled.

Quote:
If battery monitoring is not enabled, battery state is UIDeviceBatteryStateUnknown and the value of this property is 1.0.
You don't get a negative number if the battery is charging - only if you have not enabled battery monitoring.
__________________
Regards,
Duncan Champney, WareTo.
Check out our latest iOS app, Face Dancer, available for free on the App Store.
Duncan C is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 11:49 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC