ionic-team / capacitor

Build cross-platform Native Progressive Web Apps for iOS, Android, and the Web ⚡️
https://capacitorjs.com
MIT License
11.24k stars 955 forks source link

[Bug]: for plugins the removeAllListeners function does not exist on iOS #7435

Open JanMisker opened 2 weeks ago

JanMisker commented 2 weeks ago

Capacitor Version

[warn] The bundledWebRuntime configuration option has been deprecated. Can be safely deleted. 💊 Capacitor Doctor 💊

Latest Dependencies:

@capacitor/cli: 6.0.0 @capacitor/core: 6.0.0 @capacitor/android: 6.0.0 @capacitor/ios: 6.0.0

Installed Dependencies:

@capacitor/cli: 6.0.0 @capacitor/core: 6.0.0 @capacitor/ios: 6.0.0 @capacitor/android: 6.0.0

[success] iOS looking great! 👌 [success] Android looking great! 👌

Other API Details

% npm --version       
10.5.0
% node --version
v18.20.2
% pod --version
1.15.2

Platforms Affected

Current Behavior

On iOS the removeAllListeners() function on plugins is undefined, whereas on Android it exists as expected. I reproduced for PushNotifications but also checked it via console for built-in plugins like Camera.

Maybe has to do with this: https://capacitorjs.com/docs/updating/plugins/6-0#remove-removealllisteners-method

Expected Behavior

The removeAllListeners() function should work the same on iOS and Android.

Project Reproduction

https://github.com/JanMisker/TestPushNotifRemoveAll

Additional Information

No response

jcesarmobile commented 2 weeks ago

The provided app doesn't include any removeAllListeners() call, can you update it?

Are you sure you updated correctly? looks like you updated your plugins to Capacitor 6 but you are still using @capacitor/ios 5.x.

JanMisker commented 2 weeks ago

Sorry my bad I wasn't using the src dir, I modified the repository to show the issue. I just put everything in src/index.html. I do use the 6 version of ios, as you can see in the package.json.

Below screenshot of what happens when running on iOS vs. Android emulator

iOS:

Screenshot 2024-04-29 at 13 56 18

Android:

Screenshot 2024-04-29 at 13 56 50
ionitron-bot[bot] commented 2 weeks ago

This issue has been labeled as type: bug. This label is added to issues that that have been reproduced and are being tracked in our internal issue tracker.

jcesarmobile commented 2 weeks ago

Oh, yeah, since you changed the sample to not import the plugin, the common methods like removeAllListeners don't get generated since that's generated from javascript.

I guess we could generate it from native too as we do for addListeners so it's available even if the plugin is not imported.

But if you import the plugin, the removeAllListeners method is available and works as expected, the problem is just a matter of generating method for being accessible from Capacitor.Plugins.PluginName, which is technically deprecated.

JanMisker commented 2 weeks ago

One of our projects is really old and "vanilla" javascript, not using modules. So we'd have to find a way to include that generated plugin code without imports.

Still, isn't it strange that that same sample project, so without importing the plugin, does seem to work on Android? In the sense that the function is not undefined as you can see in the 2nd screenshot.

jcesarmobile commented 2 weeks ago

This is an iOS issue only, on Android the plugins methods have annotations that auto generate the javascript and removeAllListeners is one of the base plugin class methods, but on iOS no such thing exists, so they have to be generated programmatically.