Search code examples
push-notificationcross-platformintel-xdkpushwoosh

How to implement pushwoosh on xdk (intel)


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!

more information about my code:

  1. "https://github.com/Pushwoosh/pushwoosh-phonegap-3.0-plugin.git"-> I Installed the Plugin source code
  2. Whitelist *.pushwoosh.com domain in the config.xml file: ->I didn't do that because xdk should do it automatically

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
	 


Solution

  • 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.