Question

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?

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top