hello guys i am using cordova, i have create one project. my problem is that
push.on('registration', function(data) {});
this method is not calling.
i am using cordova 5.4.1, and my phone is andriod 4.1.2.
i am running my app using phonegap desktop app in laptop with phonegap developer mobile app in my mobile.
here is my project details.
cordova create pushProject
cd pushProject
cordova platform add android
cordova plugin add phonegap-plugin-push
this works fine for me.
i am using following push plugin for phonegap app
https://github.com/phonegap/phonegap-plugin-push
and i have just copied it example project in my WWW directory, which is here:
https://github.com/phonegap/phonegap-plugin-push/tree/master/example/www
also i have added cordova.js and corova_plugins.js file in WWW directory. and i have include cordova.js file in index.html file.
my index file is look like this:
<html>
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="msapplication-tap-highlight" content="no" />
<!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<!-- link rel="stylesheet" type="text/css" href="css/index.css" / -->
<link type="text/css" rel="stylesheet" href="css/materialize.min.css" media="screen,projection"/>
<title>Hello World</title>
</head>
<body>
<nav>
<div class="nav-wrapper">
<a href="#" class="brand-logo">Push Demo</a>
</div>
</nav>
<div class="row">
<div class="col s12 m6">
<div class="card darken-1">
<div class="card-content black-text">
<span class="card-title black-text">Registration ID</span>
<p id="regId">Requested</p>
</div>
</div>
</div>
</div>
<div id="cards"></div>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="js/materialize.min.js"></script>
<script type="text/javascript" src="js/index.js"></script>
</body>
</html>
and my index.js file look like this:
var app = {
// Application Constructor
initialize: function() {
this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicitly call 'app.receivedEvent(...);'
onDeviceReady: function() {
alert('device rady');
var push = PushNotification.init({
"android": {
"senderID": "<here is my google project id which ias enabled google could messaging api for android>"
},
"ios": {"alert": "true", "badge": "true", "sound": "true"},
"windows": {}
});
push.on('registration', function(data) {
alert("registration event");
document.getElementById("regId").innerHTML = data.registrationId;
console.log(JSON.stringify(data));
});
push.on('notification', function(data) {
console.log("notification event");
console.log(JSON.stringify(data));
var cards = document.getElementById("cards");
var card = '<div class="row">' +
'<div class="col s12 m6">' +
' <div class="card darken-1">' +
' <div class="card-content black-text">' +
' <span class="card-title black-text">' + data.title + '</span>' +
' <p>' + data.message + '</p>' +
' </div>' +
' </div>' +
' </div>' +
'</div>';
cards.innerHTML += card;
push.finish(function () {
alert('finish successfully called');
});
});
push.on('error', function(e) {
alert("push error");
});
}
};
app.initialize();