Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

in iOs isn't working properly #78

Open
BerthaBrenes opened this issue Feb 19, 2020 · 5 comments
Open

in iOs isn't working properly #78

BerthaBrenes opened this issue Feb 19, 2020 · 5 comments

Comments

@BerthaBrenes
Copy link

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
@breautek
Copy link

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

@esskar
Copy link

esskar commented May 13, 2020

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.

@platov
Copy link

platov commented Jul 26, 2022

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]];

@u01jmg3
Copy link

u01jmg3 commented Jul 26, 2022

@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

@EYALIN
Copy link

EYALIN commented Apr 11, 2023

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants