AddListener to plugin never triggers

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?

In your example you are not calling handleAction, which is what fires the event.

Also, by custom plugin you mean custom code in your project or a npm installed plugin?

If it’s custom code inside your app you have to register the plugin in Capacitor 6

It’s custom code in my project, not a npm installed plugin

I’m registering my code like this:

let actionPlugin = actionPlugin()
bridge?.registerPluginInstance(actionPlugin)

And the handleAction function is being called by a button in the iOS app ( I haven’t added the code for that as I didn’t think it relevant, but I have confirmed that the handleAction is being triggered and is triggering the enclosed notifyListeners function too)

Where are you putting the registration code?