wordpress plugin

Comments

7 comments

  • Avatar
    Max Konev

    Could you please elaborate how do you pass the badge with push notification?

  • Avatar
    mamastudios

    my question is this, when sending a notification using the pushwoosh wordpress plugin installed on website, my app based CORDOBA / PhoneGap using the plugin: PushwooshiOS.js notification is shown, but there is a badge bearing the number 1, here is the script code.

    many thanks

    function registerPushwooshIOS() { 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);
    
            //to view full push payload
            //alert(JSON.stringify(notification));
    
            //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);
            onPushwooshiOSInitialized(deviceToken);
        },
        function(status) {
            console.warn('failed to register : ' + JSON.stringify(status));
            //alert(JSON.stringify(['failed to register ', status]));
        }
    );
    
    //reset badges on start
    pushNotification.setApplicationIconBadgeNumber(0);
    

    }

    function onPushwooshiOSInitialized(pushToken) { var pushNotification = cordova.require("com.pushwoosh.plugins.pushwoosh.PushNotification"); //retrieve the tags for the device pushNotification.getTags( function(tags) { console.warn('tags for the device: ' + JSON.stringify(tags)); }, function(error) { console.warn('get tags error: ' + JSON.stringify(error)); } );

    //example how to get push token at a later time 
    pushNotification.getPushToken(
        function(token) {
            console.warn('push token device: ' + token);
        }
    );
    
    //example how to get Pushwoosh HWID to communicate with Pushwoosh API
    pushNotification.getPushwooshHWID(
        function(token) {
            console.warn('Pushwoosh HWID: ' + token);
        }
    );
    
    //start geo tracking.
    //pushNotification.startLocationTracking();
    

    }

  • Avatar
    Max Konev

    Which plugin for Wordpress do you use?

    you can try to call this function with the different number (other from 0):

    pushNotification.setApplicationIconBadgeNumber(0);
    
  • Avatar
    mamastudios

    Hi,

    i use: https://wordpress.org/plugins/push-notifications/

    I try to edit the script with your suggestion.

    Thank you so much

    Matteo

  • Avatar
    mamastudios

    great work fine! Thanks a lot :)

  • Avatar
    mamastudios

    Hi shader,

    Unfortunately, the change is not working. If I change "pushNotification.setApplicationIconBadgeNumber(0);" in //set push notification callback before we initialize

    the plugin when i sending a notification the badge is not shown.

    If I change "pushNotification.setApplicationIconBadgeNumber(0);" in //register for pushes

    the number displayed when the application starts even if I have not yet sent notification and no longer disappears.

    How can I fix? There is another script to add?

    Many Many thanks Matteo

  • Avatar
    mamastudios

    the script I posted above is in the file PushwooshiOS.js index.js in my file I have the following script. the badge is displayed only when Panel pushwoosh Set value manually, but when sending the notification using the wordpress plugin (https://it.wordpress.org/plugins/push-notifications/) the badge does not appear.

    you should maybe change the wordpress plugin?

    Thanks a lot

    Handlebars.registerHelper("debug", function(optionalValue) { console.log("Current Context"); console.log("===================="); console.log(this);

    if (optionalValue) { console.log("Value"); console.log("===================="); console.log(optionalValue); } });

    function initPushwoosh() { var pushNotification = cordova.require("com.pushwoosh.plugins.pushwoosh.PushNotification"); if (device.platform == "Android") { registerPushwooshAndroid(); }

    if (device.platform == "iPhone" || device.platform == "iOS") {
        registerPushwooshIOS();
    }
    
    if (device.platform == "Win32NT") {
        registerPushwooshWP();
    }
    
    pushNotification.getLaunchNotification(
        function(notification) {
            if (notification != null) {
                //alert(JSON.stringify(notification));
            } else {
                //alert("No launch notification");
            }
        }
    );
    

    }

    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 explicity call 'app.receivedEvent(...);' onDeviceReady: function() { initPushwoosh(); app.receivedEvent('deviceready'); }, // 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);
    },
    
    blog: function(){
        function getBlogs() {
            var dfd = $.Deferred();
            $.ajax({
                url: '----',
                type: 'GET',
                dataType: 'json',
                success: function(data){
                    var source   = $("#blog-template").html();
                    var template = Handlebars.compile(source);
                    var blogData = template(data);
                    $('#blog-data').html(blogData);
                    $('#blog-data').trigger('create');
                    dfd.resolve(data);
    
                },
                error: function(data){
                    console.log(data);
                }
            });
            return dfd.promise();
        };
    
        getBlogs().then(function(data){
            $('#all-posts').on('click','li', function(e){                
                localStorage.setItem('postData', JSON.stringify(data.posts[$(this).index()]));
            });
        });
    
    },
    
    single: function() {
    
            var postDataStorage = localStorage.getItem('postData');
            var source   = $("#single-template").html();
            var template = Handlebars.compile(source);
            var postData = template(JSON.parse(postDataStorage));    
            $('#single-data').html(postData);
    
    }
    

    };

Please sign in to leave a comment.