【问题标题】:Windows Phone 8.1 Plugin: class not foundWindows Phone 8.1 插件:找不到类
【发布时间】: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


    【解决方案1】:

    得到衬衫 - 我确定....

    Visual Studio 有一个讨厌的习惯,那就是真的弄乱你的 config.xml,尤其是插件。我也发现版本是随机更新的。

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

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

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

    【讨论】:

    • 嗨,之前已经尝试在科尔多瓦本身中使用它并获得相同的结果......这是一个仅限 wp8 的项目,所以我认为这不是原因,是的,我有同样的问题使用我的配置文件,但在大多数情况下它与插件一起部署.. 但是感谢您的帮助:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-20
    相关资源
    最近更新 更多