Hello, I have a Jquery mobile cordova(phonegap) application that manages to receive push notifications. One requirement is that the application should have the ability to register and unregister via button clicks. So my device fires off the standard pushNotification.registerDevice function on device ready:

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: "GOOGLE_PROJECT_ID", appid : "PUSHWOOSH_APP_ID" });

//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]));
    }
);

}

Which is all working amazingly but when i make a call using function .unregister (only available to android) nothing really happens/same goes for register.

So my question is will a function like the one below work for unregistering push notifications on button click/And would an opposite register button work?

//START OF CODE

$(function () {

$('#UnRegisterP').click(function (e) {
    var pushNotification = window.plugins.pushNotification;
    swal("Un-Registration Complete!", "You will no longer recieve push notifications!", "success");
    //initialize Pushwoosh with projectid: "GOOGLE_PROJECT_ID", appid : "PUSHWOOSH_APP_ID". This will trigger all pending push notifications on start.
    pushNotification.onDeviceReady({ projectid: "GOOGLE_PROJECT_ID", appid: "PUSHWOOSH_APP_ID" });

    //register for pushes
    pushNotification.unregisterDevice(
        function (status) {
            var pushToken = status;
            console.warn('push token: ' + pushToken);
            swal("Un-Registration Complete!", "You will no longer recieve push notifications!", "success");
        },
        function (status) {
            console.warn(JSON.stringify(['failed to register ', status]));
            swal("Error: Registering...", "Something went wrong", "error");
        }
    );
});

});

//end of code

The guide I followed: https://www.pushwoosh.com/programming-push-notification/android/android-additional-platforms/phonegapcordova-sdk-integration/

Additional info:

  • Working in visual studio using multi hybrids apps (Cordova application).
  • Application started as phonegap and transitioned to corodova (there are the same though essentially).
  • I use Jquery and Jquery mobile for the main UI/Functionality of the application.

I know unregister doesn't exist out of the box aside for android (yet to get it working ofc). I also had a look at these examples: https://github.com/Pushwoosh/pushwoosh-sdk-samples/tree/master/Phonegap-Cordova

But register and un-register methods used in that android application also do not work, plus I really wanted it be off a jquery btn.click() event.

Any help on this would be greatly appreciated :)

Kind Regards Shaun.

asked 27 Oct '14, 01:07
TkBot's gravatar image

TkBot
1612

Got it all working, can't exactly remember what the issues were unfortunately as that project is already over. Thanks for the help though :)

permanent link
answered 24 Nov '14, 23:17
TkBot's gravatar image

TkBot
1612

edited 24 Nov '14, 23:18

I'm not sure - does register function works for you? It should work as you explained.

permanent link
answered 24 Nov '14, 11:46
shader's gravatar image

shader
3.9k7

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:

×190
×165
×76
×21
×3

question asked: 27 Oct '14, 01:07

question was seen: 3,407 times

last updated: 24 Nov '14, 23:18