Capacitor: How to call custom native code

Created on 3 Aug 2018  路  3Comments  路  Source: ionic-team/capacitor

I just tried out the custom native code feature and I love it!
But I have one question. After developing a custom plugin, how to use it? The Capacitor way would be:

const { MyPlugin } = Plugins;

But now I'm getting a build error because MyPlugin is not included in the Plugin Registry. As a workaround I added the plugin definition to the file core-plugin-definitions.d.ts, afterwards my web app compiled again. But it's not good practice to edit files inside the node-modules folder.

Any suggestions how to use a custom plugin without having to touch the node-modules folder? Or is there anything else I'm missing?

All 3 comments

Ideally you should create a plugin and publish it to npm, then you can npm install it and use it like this:
import { YourCustoPlugin } from 'your-custom-plugin'; YourCustoPlugin.doSomethingAwesome();

@jcesarmobile Can we reopen this? According to the guide, I can run WebView Accessible Native Code. However my code alwarys calls the web implementation instead of the iOS implementation when I follow that guide.

No, create a new issue providing more information (like steps you have followed and a sample project if possible)

Was this page helpful?
0 / 5 - 0 ratings