I set BatteryMonitoringEnabled to True before accessing the battery information.

The documentation says that -1 should be returned only if the monitoring hasn't been enabled.

However, I always get -1 as the value of BatteryLevel property and Unknown as BatteryState, despite that I enabled the monitoring.

UIDevice.CurrentDevice.BatteryMonitoringEnabled=true;

Console.WriteLine (UIDevice.CurrentDevice.BatteryLevel.ToString());

Result -1

Console.WriteLine (UIDevice.CurrentDevice.BatteryState.ToString());

Result "Unknown"

Anything I'm missing here?

有帮助吗?

解决方案

This works for me. Could you be running this inside the iOS simulator ? If so what's you're observing would be normal results.

If you cannot this to work please fill a bug report @ http://bugzilla.xamarin.com and state which version of MonoTouch, devices, iOS versions are in use.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top