Phonegap错误添加模块

时间:2014-06-09 12:44:58

标签: cordova phonegap-plugins phonegap-build

尝试从build.phonegap.com/plugins/414添加模块。 但是在将<gap:plugin name="com.badrit.macaddress" version="0.1.0" />添加到config.xml并将try { window.MacAddress.getMacAddress( function(macAddress) {alert(macAddress);},function(fail) {alert(fail);} ); } catch {...添加到index.html之后,我收到了错误&#34;未找到类&#34; 帮助我

的index.html

<!DOCTYPE html>
<html>
  <head>
    <title>navigator.network.connection.type Example</title>

<script src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">

    // Wait for PhoneGap to load
    // 
    document.addEventListener("deviceready", onDeviceReady, false);

    // PhoneGap is loaded and it is now safe to make calls PhoneGap methods
    //
    function onDeviceReady() {
        checkConnection();
    }

    function checkConnection() {
        alert('all ok');
        try{
            window.MacAddress.getMacAddress(
            function(macAddress) {alert(macAddress);},function(fail) {alert(fail);}
            );

        } catch(e) {
            alert(e.name)
        } finally {
            alert("finished")
        }


    }



    </script>
  </head>
  <body>
    <p></p>
  </body>
</html>

config.xml中

<?xml version="1.0" encoding="UTF-8" ?>
    <widget xmlns   = "http://www.w3.org/ns/widgets"
        xmlns:gap   = "http://phonegap.com/ns/1.0"
        id          = ""
        versionCode = "10" 
        version     = "1.0.0" >
    <preference name="phonegap-version" value="3.3.0" />
    <!-- versionCode is optional and Android only -->

    <name>PhoneGap Example</name>

    <description>
        An example for phonegap build docs. 
    </description>

    <author href="https://build.phonegap.com" email="support@phonegap.com">
        Hardeep Shoker 
    </author>
<gap:plugin name="org.apache.cordova.device" /> 
<gap:plugin name="org.apache.cordova.network-information" version="0.2.7" />
<gap:plugin name="com.badrit.macaddress" version="0.1.0" />
<gap:platform name="ios" />
<gap:platform name="android" />
</widget>

2 个答案:

答案 0 :(得分:1)

在index.html中,包含插件脚本,如下所示:

<script type="text/javascript" src="MacAddress.js"></script>

答案 1 :(得分:1)

因为找不到MacAddress.js

首先必须找到路径文件夹MacAddress.js,

这是我从index.html plugins \ com-badrit-macaddress \ www \ MacAddress.js 的路径,并包含此文件您需要访问的macaddress