cordova-plugin-battery-status icon indicating copy to clipboard operation
cordova-plugin-battery-status copied to clipboard

in iOs isn't working properly

Open BerthaBrenes opened this issue 5 years ago • 5 comments

Bug Report

Problem

The plugging isn't working on iOS devices, the code haven't been update after 7 years

What is expected to happen?

Its suppose to show the battery status

What does actually happen?

Doesn't show anything, no even a simple console log in the function

Information

node v12.16.1 npm 6.13.4 ionic CLI 6.0.2

Command or Code

here my simple code this.batteryStatus.onChange().subscribe(status => { console.log("Estado Bateria"); console.log(status.level, status.isPlugged); this.batteryText = status.level; this.cdr.detectChanges(); });

Environment, Platform, Device

  • [X ] I searched for existing GitHub issues
  • [ X] I updated all Cordova tooling to most recent version
  • [ X] I included all the necessary information above

BerthaBrenes avatar Feb 19 '20 22:02 BerthaBrenes

Can you confirm that you see the same behaviour on a sample pure-cordova app (using no frameworks like ionic)? This will help us confirm that the issue is indeed with this plugin, and not something between else in between. Thanks.

https://github.com/apache/cordova-contribute/blob/master/create-reproduction.md

breautek avatar Feb 19 '20 23:02 breautek

I can partially confirm it. iOS behaves like this: when you subscribe to the event, initially no update is triggered. only when the battery status changes (like battery drains or device is plugged in/out) the battery status update is fired.

this is one pure-cordova app, ios 13. on device and simulator.

looks like #77 adresses this problem.

esskar avatar May 13 '20 19:05 esskar

Here is a trick on how to immediately obtain current battery status on IOS:

window.addEventListener("batterystatus", emptyFunc);
window.removeEventListener("batterystatus", emptyFunc); // <-- this line force Plugin to obtain actual status

// Now subscribe again and immediately receive the actual status
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]];

platov avatar Jul 26 '22 12:07 platov

@platov: thanks for the tip but this did not work for me

I still have to wait for the status to change by +/- 1%

Really we need PR #77 to be merged

u01jmg3 avatar Jul 26 '22 21:07 u01jmg3

@u01jmg3 @platov @esskar @BerthaBrenes @breautek Instead of maintaining this plugin only for me, I published a new maintained plugin called "community-cordova-plugin-battery-status" (https://github.com/EYALIN/community-cordova-plugin-battery-status) which is maintained and will keep being. please feel free to use it, and write me any feedback. can be installed by using "cordova plugin add community-cordova-plugin-battery-status" all Android and IOS recent issues are fixed there.

EYALIN avatar Apr 11 '23 13:04 EYALIN