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 get a device to even be registered at all. I've added the following plugin to my project (added in the config for phonegap build) https://github.com/phonegap/phonegap-plugin-push
I added the plugin and have following in my javascript file.
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 () {
app.receivedEvent('deviceready');
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 = '<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 () {
console.log('finish successfully called');
});
});
push.on('error', function (e) {
console.log("push error");
});
},
// Update DOM on a Received Event
receivedEvent: function (id) {
var parentElement = document.getElementById(id);
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');
listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');
console.log('Received Event: ' + id);
}
};
function successHandler(result) {
alert('result = ' + result); //Here you will get your device id.
}
function errorHandler(error) {
alert('error = ' + error);
}
So, I'm not sure where to go from here exactly. I've set up an account with push wizard and have created the additional certificates, but that is not picking up any devices as I assume there is no devices that are set to receive notifications yet.
So I guess my main issue is, am I missing something stupid like a registration stage, where my device is registered to receive notifications?