cordovapush-notificationphonegap-pluginsintel-xdkpushwoosh

implementing pushwoosh on intel xdk


How can I implement pushwoosh on intel xdk for an android app. Is there a step by step tutorial on it online. I have put the below code onto the index page, I have added the plugin, built the app and installed it on my phone but push notifications are not going through. Please help

<script>
    function onDeviceReady() {
        if( navigator.splashscreen && navigator.splashscreen.hide ) {   // Cordova API detected
            navigator.splashscreen.hide() ;
        }
        if( window.intel && intel.xdk && intel.xdk.device ) {           // Intel XDK device API detected, but...
            if( intel.xdk.device.hideSplashScreen )                     // ...hideSplashScreen() is inside the base plugin
                intel.xdk.device.hideSplashScreen() ;
        }

        initPushwoosh();
    }
    document.addEventListener("deviceready", onDeviceReady, false) ;



    function initPushwoosh() 
    {
        var pushNotification = cordova.require("com.pushwoosh.plugins.pushwoosh.PushNotification");

        //set push notification callback before we initialize the plugin
        document.addEventListener('push-notification', function(event) {
            //get the notification payload
            var notification = event.notification;

            //display alert to the user for example
            alert(notification.aps.alert);

            //clear the app badge
            pushNotification.setApplicationIconBadgeNumber(0);
        });

        //initialize the plugin
        pushNotification.onDeviceReady({pw_appid:"****-****"});

        //register for pushes
        pushNotification.registerDevice(
            function(status) {
                var deviceToken = status['deviceToken'];
                console.warn('registerDevice: ' + deviceToken);
            },
            function(status) {
                console.warn('failed to register : ' + JSON.stringify(status));
                alert(JSON.stringify(['failed to register ', status]));
            }
        );

        //reset badges on app start
        pushNotification.setApplicationIconBadgeNumber(0);
    }

</script>

Solution

  • I just implemented this yesterday as well and it works fine. Here's what I did to make it easy.

    1. Add the third party plug in in the projects tab. I used the registered cordova plug in to make it easy not the github plugin.
    2. Get the certificates (iOS) and credentials (Android) as outlined in the respective configuration guides. (iOS https://www.pushwoosh.com/programming-push-notification/ios/ios-configuration-guide/ and Android https://www.pushwoosh.com/programming-push-notification/android/android-gcm-api-configuration/
    3. Then follow the instructions for iOS and android phonegap / cordova implementation. I didn't use the instructions exactly, I basically downloaded the example files and created the same files in my project (index.js, PushwooshAndroid.js, PushwooshiOS.js)
    4. Change the app id's and other specific ids for your platform in the index.js file.
    5. In the index.html file I added these scripts

    6. I put them in the body not the header. Then added this line to my init function under deviceready: document.addEventListener("deviceready", initPushwoosh, true);

      That's it. It worked. I do have problems with it initializing each time but other than that it works.