Windows Phone 8.1插件:找不到类

时间:2015-07-10 09:20:58

标签: javascript c# cordova windows-phone-8.1 cordova-plugins

我在以下代码中遇到以下问题:

的plugin.xml

i

BarcodeScanner.js

<?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.cs

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;

index.js

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);
        }
    }
}

以及以下环境:

适用于VS13的Cordova Tools Cordova版本:5.0.0和4.1.2(在VS13中)

Target是带有Windows Phone 8.1 Embedded Handheld的Panasonic FZ-E1

当我打电话时,应用程序会打印以下内容:

  

n:没有结果   步骤1   第2步   测试1   测试2   测试2.2:未找到班级

如果我搬家:

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() {
    };
})();

到wp8段它不打印测试2.2

如果我改变:

    <config-file target="config.xml" parent="/*">
         <feature name="BarcodeScanner">
              <param name="wp-package" value="BarcodeScanner"/>
         </feature>
    </config-file>

为:

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", []);

它也不会打印测试2.2

所以我不知道究竟如何调用我的C#-Method ...我认为BarcodeScanner是正确的名称,因为XXXBarcodeScanner是该死的错误而且BarcodeScanner.BarcodeScanner似乎显示了相同的结果。你能告诉我我做错了什么吗?因为此刻我真的很无能。

此致 史蒂文彼得

1 个答案:

答案 0 :(得分:0)

得到了这件衬衫 - 我确定......

Visual Studio有一个令人讨厌的习惯,就是在搞乱你的config.xml,尤其是插件。我还发现该版本是随机更新的。

在TEXT模式下打开config.xml,确保条形码插件引用。创建一个空白项目,如果需要并添加插件,然后检查它们是否相同。我也有这个版本信息插件,它只是不存在或版本错误。

还要养成仔细检查android,win8等版本号的习惯,因为它有时不会更新。

我真的喜欢VS,但有时它会考验我的耐心。祝你好运!