I\'m developing an App using Phonegap and Phonegap Build. The app has been pretty much completed but I\'m not working on the Push Notifications.
I\'m struggling to g
So there was 2 sections to this, First what jesseMonroy mentioned, my code wasn't being picked up properly and my js file wasn't being run properly.
The second part was that I wasn't calling a register function, which allows you to get a device_token.
push.registerDevice({ alert: true, badge: true, sound: true }, function (status) {
app.myLog.value += JSON.stringify(['registerDevice status: ', status]) + "\n";
app.storeToken(status.deviceToken);
alert(status.deviceToken)
});
This is what i was missing. my whole init section looks like this;
var push = PushNotification.init({
"android": {
"senderID": "1234567890"
},
"ios": { "alert": "true", "badge": "true", "sound": "true" },
"windows": {}
});
push.on('registration', function (data) {
console.log("registration event");
//document.getElementById("regId").innerHTML = data.registrationId;
alert(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 = '' +
'' +
' ' +
' ' +
' ' + data.title + '' +
' ' + data.message + '
' +
' ' +
' ' +
' ' +
'';
cards.innerHTML += card;
push.finish(function () {
console.log('finish successfully called');
});
});
push.on('error', function (e) {
console.log("push error");
});
// var pushNotification = window.plugins.PushNotification;
push.registerDevice({ alert: true, badge: true, sound: true }, function (status) {
app.myLog.value += JSON.stringify(['registerDevice status: ', status]) + "\n";
app.storeToken(status.deviceToken);
alert(status.deviceToken)
});