I have followed all the steps suggested on the Pushwoosh website but I still get the following error:
Uncaught TypeError: Cannot read property 'pushNotification' of undefined
Please help me!
3.Register for push notifications: Add the following function to your javascript file, enter the correct Project Number and Pushwoosh App ID
$( document ).ready(function() {
// Handler for .ready() call
initPushwoosh();
}
//push begin
function initPushwoosh(){
var pushNotification = window.plugins.pushNotification;
//set push notifications handler
document.addEventListener('push-notification', function(event) {
var title = event.notification.title;
var userData = event.notification.userdata;
if(typeof(userData) != "undefined") {
console.warn('user data: ' + JSON.stringify(userData));
}
alert(title);
});
//initialize Pushwoosh with projectid: "GOOGLE_PROJECT_ID", appid : "PUSHWOOSH_APP_ID". This will trigger all pending push notifications on start.
pushNotification.onDeviceReady({ projectid: "****", appid : "****" });
//register for pushes
pushNotification.registerDevice(
function(status) {
var pushToken = status;
console.warn('push token: ' + pushToken);
},
function(status) {
console.warn(JSON.stringify(['failed to register ', status]));
}
);
}
document.addEventListener('push-notification', function(event) {
var title = event.notification.title;
var userData = event.notification.userdata;
console.warn('user data: ' + JSON.stringify(userData));
alert(title);
});
//push end
Check if window.plugins.pushNotification is not null or undefined.
If it is null (or undefined), make sure your reference plugin correctly in config.xml ("phonegap plugin add" command should do everything for you automatically).
If you provide more information, I could improve the answer.