I am not sure what I am doing wrong but I can not get a custom Cordova plugin to work in my Ionic 2 project. I have read though a number of questions on this forum about custom plugins and Ionic 2 but nothing seems to help. I am basically trying to get real simple “Echo” plugin to work. The plugin is written using WinJS so it should work natively for Windows. I know we can do this without a plugin but I am using this to try to figure out how to write a custom plugin.
Here is my plugin’s plugin.xml file:
<?xml version='1.0' encoding='utf-8'?> <plugin id="com-myfuelmaster-fmecho" version="0.0.1" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android"> <name>FMEcho</name> <js-module name="FMEcho" src="www/FMEcho.js"> <clobbers target="fmecho" /> </js-module>
<!-- windows --> <platform name="windows"> <js-module src="src/windows/fmechopluginProxy.js" name="FMEchoProxy"> <merges target="" /> </js-module> </platform>
</plugin>
Here is the www/FMEcho.js file:
var exec = require('cordova/exec');
window.fmecho = function(arg0, success, error) { exec(success, error, "FMEcho", "echo", [arg0]); };
and the windows/fmechopluginProxy.js file:
cordova.commandProxy.add("FMEcho",{ echo:function(successCallback,errorCallback,strInput) { if(!strInput || !strInput.length) { errorCallback("Error, something was wrong with the input string. =>" + strInput); } else { successCallback(strInput + "echo"); } } });
Now I try to call it using:
window.fmecho("Hello", function (echoValue) { this.message = echoValue; // should alert true. },function(echoValue) { this.message = "Failed"; // should alert true. });
I have also tried:
windows.FMEcho
windows.FMEcho.echo
windows.echo
but when I try to build it I get the error: : Property ‘fmecho’ does not exist on type ‘Window’.
I installed the plugin using the following command: ionic plugin add …/FMEchoPlugin/FMEcho/
Any ideas of what might be wrong?