Sub GetBatteryLevel As Float
Dim no As NativeObject
no = no.Initialize("UIDevice").RunMethod("currentDevice", Null)
If no.GetField("batteryMonitoringEnabled").AsBoolean = False Then
no.SetField("batteryMonitoringEnabled", True)
End If
Return no.GetField("batteryLevel").AsNumber
End Sub
I just did some testing and found that different iOS devices have different levels of granularity. The iPhone 4 I was testing has 5% not the original 10% I listed above.
iPhone 4 (MD146LL/A) has 5% steps (1.0 -> 0.95 ->0.90) Even though the battery gauge on notification line steps in 1% units
iPad (Model MC981LL/A) has 1% steps (1.0 ->0.99 -> 0.98)
'0 = Unknown
'1 = Unplugged
'2 = Charging
'3 = Full
Sub GetBatteryState As Int
Dim no As NativeObject
no = no.Initialize("UIDevice").RunMethod("currentDevice", Null)
If no.GetField("batteryMonitoringEnabled").AsBoolean = False Then
no.SetField("batteryMonitoringEnabled", True)
End If
Return no.GetField("batteryState").AsNumber
End Sub