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 :
Uncaught ReferenceError: Cordova is not defined at file:///android_asset/www/GCMPlugin.js
this is my 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 :
function register()
{ window.plugins.GCM.register("1193127317675", "GCM_Event", GCM_Success, GCM_Fail ); }
this is my 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
! 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
Uncaught ReferenceError: Cordova is not defined at file:
Seems you forgot to add cordova js script to your assets folder.
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 ).
For cordova 3.0 you just have to add this lines to your res/xml/config.xml file.
<feature name="GCMPlugin">
<param name="android-package" value="com.plugin.GCM.GCMPlugin" />
</feature>
Instead of <plugin name="GCMPlugin" value="com.plugin.GCM.GCMPlugin" />
That's because of <plugin>
deprecated in cordova 3.*
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.