0

I did all the required steps to create new cordova plugin as mentioned in the below question and I succeed:

Start android activity from cordova plugin

I ran the following command cordova plugin ls and I got the following result:

com.example.sample.plugin 0.0.1 "PluginName"

So my plugin is added to my project.

But still I am not able to import it in the .ts file my ionic 4 project. What import statement should I write to be able to use the plugin?

Ali Wehbi
  • 69
  • 1
  • 11

1 Answers1

0

Try:

// at the top of your file outside of any class definitions
declare var cordova: any;

cordova.plugins.SignInWithApple.function();

I believe it takes the plugin name from the tag, for example:

<js-module src="www/sign-in-with-apple.js" name="SignInWithApple">
  • didn't work. should i add cordova.plugins.SignInWithApple.function(); in home.js file in the assets folder for example? – Ali Wehbi Mar 23 '21 at 12:40
  • @AliWehbi no what i meant was you can call your plugin like this. you add `declare var cordova: any;` at the top of your calling file, and then wherever you want to call your function you use `cordova.plugins.YourPluginName.yourFunctionName();`. `YourPluginName` should match what is in the tag that describes your plugin in the config.xml. – Ameesh Kapoor Sep 01 '21 at 21:26