簡體   English   中英

Windows Phone 8.1插件:找不到類

[英]Windows Phone 8.1 Plugin: class not found

我使用以下代碼遇到以下問題:

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段,它不會打印測試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#方法...我認為BarcodeScanner是正確的名稱,因為XXXBarcodeScanner真是該死,BarcodeScanner.BarcodeScanner似乎顯示了相同的結果。 你能告訴我我做錯了嗎? 因為此刻我真的很笨。

問候,史蒂文·彼得

得到了襯衫-我確定。

Visual Studio有一個討厭的習慣,就是要弄亂您的config.xml,尤其是插件。 我還發現該版本是隨機更新的。

在TEXT模式下打開config.xml,並確保其中有條形碼插件參考。 如果需要,請創建一個空白項目,並添加插件,然后檢查它們是否相同。 我在版本信息插件中也遇到了這個問題,只是那里不存在或版本錯誤。

還要養成仔細檢查android,win8等版本號的習慣,因為有時它不會更新。

我真的很喜歡VS,但是有時候它測試了我的耐心。 祝好運!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM