【发布时间】:2015-07-10 09:20:58
【问题描述】:
我对以下代码有以下问题:
plugin.xml
<?xml version="1.0" encoding="utf-8" ?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="barcodescanner-plugin"
version="0.0.1">
<name>Barcode Scanner Plugin</name>
<description>Cordova Barcode Scanner Plugin...</description>
<author>XXX</author>
<license>BSD</license>
<config-file target="config.xml" parent="/*">
<feature name="BarcodeScanner">
<param name="wp-package" value="BarcodeScanner"/>
</feature>
</config-file>
<js-module src="www/BarcodeScanner.js" name="BarcodeScanner">
<clobbers target="window.BarcodeScanner" />
</js-module>
<plattform name="wp8">
<config-file target="Properties/WMAppManifest.xml" parent="/Deployment/App/Capabilities">
<Capability Name="pointOfSale"/>
</config-file>
<source-file src="src/wp/BarcodeScanner.cs" />
<framework src="lib/Windows.Devices.PointOfService.winmd" />
<framework src="lib/WPCordovaClassLib.dll" />
</plattform>
</plugin>
BarcodeScanner.js
var exec = require('cordova/exec');
var BarcodeScanner = {
result: "No Result available<br />",
Enable: function () {
try {
var that = this;
this.result += "Test 1<br />";
exec(function () { that.result += "Test 2.1"; }, function (error) { that.result += "Test 2.2: " + error; }, "BarcodeScanner", "Enable", []);
this.result += "Test 2<br />";
} catch (e) {
this.result += "Exception occured<br />";
this.result += e.message + "<br />";
}
}
}
module.exports = BarcodeScanner;
BarcodeScanner.cs
using WPCordovaClassLib.Cordova;
using WPCordovaClassLib.Cordova.Commands;
using WPCordovaClassLib.Cordova.JSON;
namespace WPCordovaClassLib.Cordova.Commands
{
public class BarcodeScanner : BaseCommand
{
public void Enable(string options)
{
PluginResult result = new PluginResult(PluginResult.Status.OK, "Test... Test...");
DispatchCommandResult(result);
}
}
}
index.js
var i = 0;
function updateOutputText() {
document.getElementById("output").innerHTML = i + ": " + window.BarcodeScanner.result;
i++;
}
window.setInterval(updateOutputText, 1000);
(function () {
"use strict";
document.addEventListener('deviceready', onDeviceReady.bind(this), false);
function onDeviceReady() {
window.BarcodeScanner.result += "Step 1<br />";
// Handle the Cordova pause and resume events
document.addEventListener('pause', onPause.bind(this), false);
document.addEventListener('resume', onResume.bind(this), false);
window.BarcodeScanner.result += "Step 2<br />";
window.BarcodeScanner.Enable();
};
function onPause() {
};
function onResume() {
};
})();
以及以下环境:
用于 VS13 的 Cordova 工具 Cordova 版本:5.0.0 和 4.1.2(在 VS13 中)
目标是带有 Windows Phone 8.1 嵌入式手持设备的 Panasonic FZ-E1
当我调用它时,应用程序会打印以下内容:
n:没有可用的结果 第1步 第2步 测试 1 测试 2 测试 2.2:找不到类
如果我搬家:
<config-file target="config.xml" parent="/*">
<feature name="BarcodeScanner">
<param name="wp-package" value="BarcodeScanner"/>
</feature>
</config-file>
到 wp8 段,它不打印 Test 2.2
如果我改变:
exec(function () { that.result += "Test 2.1"; }, function (error) { that.result += "Test 2.2: " + error; }, "BarcodeScanner", "Enable", []);
到:
exec(function () { that.result += "Test 2.1"; }, function (error) { that.result += "Test 2.2: " + error; }, "BarcodeScanner.BarcodeScanner", "Enable", []);
或
exec(function () { that.result += "Test 2.1"; }, function (error) { that.result += "Test 2.2: " + error; }, "XXXBarcodeScanner", "Enable", []);
它也不打印测试 2.2
所以我现在不确切知道如何调用我的 C#-Method... 我认为 BarcodeScanner 是正确的名称,因为 XXXBarcodeScanner 是该死的错误,而 BarcodeScanner.BarcodeScanner 似乎显示相同的结果。你能告诉我我做错了什么吗?因为现在我真的很无知。
问候, 史蒂文·彼得
【问题讨论】:
标签: javascript c# cordova windows-phone-8.1 cordova-plugins