You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by GitBox <gi...@apache.org> on 2022/07/26 12:32:01 UTC
[GitHub] [cordova-plugin-battery-status] platov commented on issue #78: in iOs isn't working properly
platov commented on issue #78:
URL: https://github.com/apache/cordova-plugin-battery-status/issues/78#issuecomment-1195422269
Here is a trick on how to obtain current battery status on IOS without need of waiting of change event:
```javascript:
window.addEventListener("batterystatus", emptyFunc);
window.removeEventListener("batterystatus", emptyFunc); // <-- this line force Plugin to obtain actual status
// Now read the actual status
const level = navigator.battery._level;
const isPlugged = navigator.battery._isPlugged;
// listen on further status updates.
window.addEventListener("batterystatus", onBatteryStateChange);
```
Why unsubscribe forces to read the status ?
When we do unsubscribe from `batterystatus` event and no more listeners available then plugin calls `stop` command that actually does:
```
CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:[self getBatteryStatus]];
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org