简体   繁体   English

您好如何为我提供帮助并解决“ file:///android_asset/www/plugin.js中未定义Cordova.exec()”错误

[英]hi how can help me and resolve “Cordova.exec() is not defined at file:///android_asset/www/plugin.js” error

i was trying to implement a simple push notification application using some plugins. 我试图使用一些插件来实现一个简单的推送通知应用程序。 a this moment i have an problem with a javaScript file when i click on a bouton how call a javaScript function called register , that show me an error : 此时此刻,当我单击一个按钮如何调用名为register的javaScript函数时,我遇到了javaScript文件问题,这向我显示了一个错误:

Uncaught ReferenceError: Cordova is not defined at file:///android_asset/www/GCMPlugin.js

this is my GCMPlugin.js 这是我的GCMPlugin.js

        (function () {

    var GCM = function() {};

    GCM.prototype.register = function(senderID, eventCallback, successCallback, failureCallback) {

      if ( typeof eventCallback != "string") {   // The eventCallback has to be a STRING name not the actual routine like success/fail routines
        var e = new Array();
        e.msg = 'eventCallback must be a STRING name of the routine';
        e.rc = -1;
        failureCallback( e );
        return;
      }

      return Cordova.exec(successCallback,      
                  failureCallback,      
                  'GCMPlugin',        
                  'register',             
                  [{ senderID: senderID, ecb : eventCallback }]);   
                                };

    if (cordova.addPlugin) {
      cordova.addConstructor(function() {
        //Register the javascript plugin with Cordova
        cordova.addPlugin('GCM', new GCM());
      });
    } else {
        if (!window.plugins) {
            window.plugins = {};
        }
      window.plugins.GCM = new GCM();
    }
})();

the function register in index.js : 在index.js中的功能寄存器:

function register()
{ window.plugins.GCM.register("1193127317675", "GCM_Event", GCM_Success, GCM_Fail ); }

this is my index.html : 这是我的index.html:

<!DOCTYPE HTML>
<html>
<head>
<title>M W A</title>
<script type="text/javascript" charset="utf-8" src="cordova-2.1.0.js"></script>
<script src="GCMPlugin.js"></script> <!-- GCM Cordova plugin -->
<script type="text/javascript" charset="utf-8" src="jquery_1.5.2.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/index.css" />
<!-- Include my Javascript routines -->
<script type="text/javascript" charset="utf-8" src="PushNotification.js"></script>
<script type="text/javascript" charset="utf-8" src="CORDOVA_GCM_script.js"></script>

</head>
<body>
        <script type="text/javascript" src="js/index.js"></script>
        <script type="text/javascript">
            app.initialize();
        </script>

        <input type="button" value="Register" style="width: 200px; height: 100px;" onclick="register();" >
        <input type="button" value="Unregister" style="width: 200px; height: 100px;" onclick="unregister();" >
</body>
</html>

note : that i use cordova-2.1.0.js ! 注意:我使用cordova-2.1.0.js and when i use cordova.js (3.0.0) i get that exec() call to unknown plugin: GCMPlugin can u help me to resolve this problem .. i spend more than 3 days to resolve it but i still have this problem 当我使用cordova.js (3.0.0)时,我得到那个exec() call to unknown plugin: GCMPlugin你能帮我解决这个问题exec() call to unknown plugin: GCMPlugin ..我花了3天多的时间来解决它,但是我仍然有这个问题

Uncaught ReferenceError: Cordova is not defined at file: 未捕获的ReferenceError:在文件中未定义Cordova:

Seems you forgot to add cordova js script to your assets folder. 似乎您忘记了将cordova js脚本添加到资产文件夹中。

If you want to use GCM, you should do the following: At first, you should have installed GCM plugin ( https://github.com/marknutter/GCM-Cordova ). 如果要使用GCM,则应执行以下操作:首先,应已安装GCM插件( https://github.com/marknutter/GCM-Cordova )。

For cordova 3.0 you just have to add this lines to your res/xml/config.xml file. 对于cordova 3.0,您只需要将此行添加到res / xml / config.xml文件中。

<feature name="GCMPlugin">
        <param name="android-package" value="com.plugin.GCM.GCMPlugin" /> 
</feature>

Instead of <plugin name="GCMPlugin" value="com.plugin.GCM.GCMPlugin" /> 代替<plugin name="GCMPlugin" value="com.plugin.GCM.GCMPlugin" />

That's because of <plugin> deprecated in cordova 3.* 这是因为Cordova 3.中不推荐使用<plugin>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Phonegap:对象xx在文件中没有方法&#39;exec&#39;:///android_asset/www/cordova.js - Phonegap: Object xx has no method 'exec' at file:///android_asset/www/cordova.js “初始化网络连接时出错:找不到类”,来源:file:///android_asset/www/cordova.js - “Error initializing Network Connection: Class not found”, source: file:///android_asset/www/cordova.js 错误回调中的错误:TestPlugin2 = ReferenceError:找不到变量:登录文件:///android_asset/www/js/cordova-1.6.1.js:276 - Error in error callback: TestPlugin2 = ReferenceError: Can't find variable: log at file:///android_asset/www/js/cordova-1.6.1.js:276 Phonegap / Android错误:未捕获ReferenceError:未在file:///android_asset/www/js/login.js:17定义url - Phonegap/Android error: Uncaught ReferenceError: url is not defined at file:///android_asset/www/js/login.js:17 LeafLet错误:对象# <Object> 在file:///android_asset/www/leaflet.js:6没有方法&#39;onAdd&#39; - LeafLet Error : Object #<Object> has no method 'onAdd' at file:///android_asset/www/leaflet.js:6 Reactjs-router-dom和cordova始终直接指向file:///android_asset/www/index.html - Reactjs-router-dom and cordova always direct to file:///android_asset/www/index.html 未捕获的TypeError:对象#<Object>在file:///android_asset/www/index.html上没有方法'exec' - Uncaught TypeError: Object #<Object> has no method 'exec' at file:///android_asset/www/index.html 无法在文件:///android_asset/www/apis/camera.js:45读取未定义类型的属性“ DATA_URL” - Can not read propery 'DATA_URL' of undefined type at file:///android_asset/www/apis/camera.js:45 未捕获的ReferenceError:在文件:///android_asset/www/index.html:27上未定义show_pic - Uncaught ReferenceError: show_pic is not defined at file:///android_asset/www/index.html:27 在phonegap中的file://android_asset/www/index.html上未定义函数 - function is not defined at file://android_asset/www/index.html in phonegap
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM