I have a custom plugin on iOS that I need to use to trigger some JS code to run on my web app, however the addListener
method is never being triggered and I don’t understand why. This is the code I have in iOS:
Plugin
import Capacitor
@objc(ActionPlugin)
public class ActionPlugin: CAPPlugin {
@objc
func handleAction(_ action: String) {
self.notifyListeners("action", ["action": action])
}
}
Objective-C plugin
#import <Foundation/Foundation.h>
#import <Capacitor/Capacitor.h>
CAP_PLUGIN(ActionPlugin, "ActionPlugin",;)
And this is what I have in web app:
import { PluginListenerHandle, registerPlugin } from '@capacitor/core';
export type ActionData = {
action: string;
};
export interface ActionPlugin {
addListener(eventName: 'action', listenerFunc: (data: ActionData) => void): Promise<PluginListenerHandle>;
}
const Action = registerPlugin<ActionPlugin>("ActionPlugin");
export { Action };
Listener (this is never triggered)
Action.addListener('action', (info: any) => {
console.log('Action triggered');
});
Does anyone know why my listener is never being triggered? Is there something I’ve missed?