Pushing notification with phonegap from app

Answered

Comments

3 comments

  • Avatar
    Max Kuzakov

    Hello,

    Please note that for now sending notifications from within the app is available with our Native Android SDK only. Our PhoneGap plugin does not support this functionality.

    Please take a look at the Javascript snippet below - it can be useful in case of using Cordova:

    $.ajax({
        type: "POST",
        url: "https://cp.pushwoosh.com/json/1.3/createMessage",
        data: JSON.stringify({
            "request": {
                "application": "APPLICATION CODE",
                "auth": "API TOKEN",
                "notifications": [{
                    "send_date": "now",
                    "ignore_user_timezone": true,
                    "content": "Hello world!"
                }]
            }
        }),
        dataType: "json"
    }).done(function(data) {
        console.log(data);
    });
    
  • Avatar
    Bryan

    I see.. Is the Javascript snippet you provide a dynamic message or is it a static one? I'm guessing this particular snippet will send out a "Hello world!" push notification correct?

    What I mean my dynamic is, say the app asks the user what message they want to send out from within the app then it will send it out with whatever message was typed into some sort of input box.

  • Avatar
    Vitaly Romanychev

    Bryan,

    Did you try the following:

    var notification = {
    
                    send_date: "now",
                    ignore_user_timezone: true,
                    content: $('textarea#msg').val() // or $('#msg').val(), depends on how you want to obtain the content
                }
    
    $.ajax({
        type: "POST",
        url: "https://cp.pushwoosh.com/json/1.3/createMessage",
        data: JSON.stringify({
            "request": {
                "application": "APPLICATION CODE",
                "auth": "API TOKEN",
                "notifications": notification
    
            }
        }),
        dataType: "json"
    }).done(function(data) {
        console.log(data);
    });
    

Please sign in to leave a comment.