1
I am developing a Cordova plugin for windows desktop and need to use some native functions, I will have to use Windows Runtime. I started by following a tutorial and I have the following structure:
- /src
- /EchoRuntime
- /bin
- /obj
- /Properties
- EchoPluginRT.cs
- EchoRuntimeComponent.csproj
- echopluginProxy.js
- /www
- echoplugin.js
- plugin.xml
At code level I have the following:
xml plugin.
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" id="com.teste.echoplugin" version="0.1.0">
<name>EchoPlug</name>
<description>Echo demo plugin for Apache Cordova</description>
<license>MIT</license>
<keywords></keywords>
<repo></repo>
<issue></issue>
<js-module src="www/echoplugin.js" name="echoplugin">
<clobbers target="window.echoplugin" />
</js-module>
<!-- windows8 -->
<platform name="windows">
<js-module src="src/windows/echopluginProxy.js" name="EchoProxy">
<merges target="" />
</js-module>
<framework src="src/windows/EchoRuntime/EchoRuntimeComponent.csproj" custom="true" type="projectReference"/>
</platform>
/www/echoplugin.js
var EchoPlugin = {
// the echo function calls successCallback with the provided text in strInput
// if strInput is empty, it will call the errorCallback
echo:function(successCallback, errorCallback, strInput) {
cordova.exec(successCallback,errorCallback,"EchoPlugin","echo",[strInput]);
}
}
module.exports = EchoPlugin;
/src/echopluginProxy.js
cordova.commandProxy.add("EchoPlugin",{
echo:function(successCallback,errorCallback,strInput) {
var res = EchoRuntimeComponent.EchoPluginRT.echo(strInput);
if(res.indexOf("Error") == 0) {
errorCallback(res);
}
else {
successCallback(res);
}
}
});
/src/Echoruntime/Echopluginrt.Cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EchoRuntimeComponent
{
public sealed class EchoPluginRT
{
public static string echo(string valor)
{
return " PASSOU AQUI";
}
}
}
Only with Javascript can I get it working now with the C# function is not. Someone can help?
Plugin - https://github.com/claudiohilario/cordova-plugin-udp-data-response
– Cláudio Hilário