Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

xArtx

macrumors 6502a
Original poster
Mar 30, 2012
764
1
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.
 

ArtOfWarfare

macrumors G3
Nov 26, 2007
9,559
6,059
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.
 

xArtx

macrumors 6502a
Original poster
Mar 30, 2012
764
1
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.
 

Duncan C

macrumors 6502a
Jan 21, 2008
853
0
Northern Virginia
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.
 

xArtx

macrumors 6502a
Original poster
Mar 30, 2012
764
1
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.

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.
 

Duncan C

macrumors 6502a
Jan 21, 2008
853
0
Northern Virginia
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.

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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.