Push Notification not working

  • Good morning,

    I am currently trying to integrate push notification for the app "uAdBlock". For this I proceeded like in the Wiki.
    Now I have a token. To test if everything works, I wanted to send a test message with this snippet:

    var req = new XMLHttpRequest();
    req.open("post", "https://push.ubports.com/notify", true);
    req.setRequestHeader("Content-type", "application/json");
    req.onreadystatechange = function() {
        if ( req.readyState === XMLHttpRequest.DONE ) {
            console.log("✍ Answer from push service:", req.responseText)
            var ans = JSON.parse(req.responseText)
            if ( ans.error ) {
                if ( ans.message ) {
    var approxExpire = new Date ()
        "appid" : 'uadblock.mariogrip_uAdBlock',
        "expire_on": approxExpire.toISOString(),
        "token": 'TOKEN',
        "data": {
            "notification": {
                "card": {
                    "icon": "notification",
                    "summary": "Push Notification",
                    "body": "test",
                    "popup": true,
                    "persist": true
                "vibrate": true,
                "sound": true

    But nothing happens and in the console the answer from the server is empty. Have I forgotten anything? Maybe someone can help me?

  • Maybe you @Krille

  • @beli3ver Not much of experience with C, but is that correct: "if ( req.readyState === XMLHttpRequest.DONE )"? Shouldn't be "==" ?

  • @C0n57an71n as the code snippet posted is JavaScript, "===" is correct.

  • You did not set the token to the actual token and you just put the string TOKEN.
    I compare to my Pesbuk code and I think that's the main difference.

    You can check here.

  • Ok I wrote TOKEN to not post my real token.

    But I think I found my mistake. I guess that the code snippet must be in the app as well?

    Currently I'm running it on the server and thought that this way I send notifications to the client, so I guess that was my mistake 😆

  • @kugiigi maybe you can help me.
    I am really stuck.
    I have integrated Push Notifications as it is written in the Wiki. I also have a function that sends the token to my server, I get that too.

    Now the question, the function above is used to send a notification from my server to the Ubuntu server or does this code have to be called into the app because it gets called when the Ubuntu server sends a notification to the app?

  • @beli3ver Oh I see, I didn't think of that 😅

    My app executes this code because it's actually just a workaround for having push notification in the webapp. I have no other experience with push notification but I think the code should actually be executed in the server but the token has to be coming from the device that should receive the notification.

  • Just to provide some reference links.

    The wiki you mentionned is probably the official documentation:

    And have you checked the example app "PushClient" ?

  • @kugiigi said in Push Notification not working:

    My app executes this code because it's actually just a workaround for having push notification in the webapp.

    Oh, could you explain a bit how that works? It is taking the web notifications and translating them to UT push? I have been scratching my head how to implement push notifications with a web-app.

  • @poVoq No not really, it's a pure hacky way. I simply injected JS codes to check the notification flags in the webpage so it needed to disable app suspension. Actually, it seems that it stopped working. Not sure if it's Facebook's fault or UT's.

  • @beli3ver your notification system works well 👍

Log in to reply