Hi,

When sending the notification by wordpress to my app (created with the pushwoosh plugin for Cordova/PhoneGap) does not show a notify counter badge... how can i do to show the counter of notification? thanks a lot

asked 04 Oct '15, 20:37
mamastudios's gravatar image

mamastudios
12

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

permanent link
answered 19 Oct '15, 21:49
shader's gravatar image

shader
3.9k7

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();

}

permanent link
answered 20 Oct '15, 08:09
mamastudios's gravatar image

mamastudios
12

Which plugin for Wordpress do you use?

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

pushNotification.setApplicationIconBadgeNumber(0);
permanent link
answered 20 Oct '15, 12:50
shader's gravatar image

shader
3.9k7

Hi,

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

I try to edit the script with your suggestion.

Thank you so much

Matteo

permanent link
answered 20 Oct '15, 13:24
mamastudios's gravatar image

mamastudios
12

great work fine! Thanks a lot :)

permanent link
answered 23 Oct '15, 06:24
mamastudios's gravatar image

mamastudios
12

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

permanent link
answered 27 Oct '15, 09:38
mamastudios's gravatar image

mamastudios
12

edited 27 Oct '15, 09:39

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);

}

};

permanent link
answered 28 Oct '15, 06:45
mamastudios's gravatar image

mamastudios
12

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×446
×165
×18

question asked: 04 Oct '15, 20:37

question was seen: 1,322 times

last updated: 28 Oct '15, 06:45