06-25-2012 05:14 AM
I'm trying to implement push notifications in a WebWorks App but without any luck. I've followed the info and the demos but still can't manage to make this work.
What I'd like to know if someone has done it and if someone has a working sample of the client app for me to guide on, and also a way to trigger a notification to that sample app.
Thanks in advance
08-09-2012 11:46 AM
I'm still in trouble getting this to work, does anyone know how to make this work?
I'd really appreciate some help!
08-09-2012 11:48 AM
Can you clarify if you are trying to develop a push app for BBOS or for BB10?
08-09-2012 11:50 AM
Hi marco,
I'm devoloping for BBOS 6 & 7
08-09-2012 11:54 AM
Ok great. With that in mind, can you provide more detail on what the exact problem you are having writing a WebWorks push enabled application? For example, are you getting stuck somewhere or are you getting a particular error code?
08-09-2012 12:04 PM
Ok, so I was following the directions pointed at https://developer.blackberry.com/html5/apis/blackb
08-09-2012 12:08 PM
Let's start with looking at your JavaScript code where you open the push listener. Can you paste that code into your next reply using the appropriate code tags?
08-09-2012 12:38 PM
Ok, so here it is. You'll find several alerts across the code. The first 3 ("open1", "open2" & "open3") appear, but not the others.
// START - Listen to push notifications var port = myport; // Replaced for example purpose var serverUrl = "http://pushapi.eval.blackberry.com"; var appId = "my_appid"; // Replaced for example purpose var max = 100; var wakeUpPage = "index.html"; openBISPushListener(); function openBISPushListener() { try { alert("open1"); var ops = {port : port, appId : appId, serverUrl : serverUrl, wakeUpPage : wakeUpPage, maxQueueCap : max}; alert("open2"); blackberry.push.openBISPushListener(ops, onData, onRegister, onSimChange); alert("open3"); } catch (err) { alert('Err: '+err); } } function onRegister(status) { if (status == 0) { alert("success"); } else if (status == 1) { alert("network error"); } else if (status == 2) { alert("rejected by server"); } else if (status == 3) { alert("invalid parameters"); } else if (status == -1) { alert("general error"); } else { alert("unknown status"); } } function onData(data) { //var resultDiv = document.getElementById("resultDiv"); try { //resultDiv.innerHTML += "<br>" + blackberry.utils.blobToString(data.payload); alert(blackberry.utils.blobToString(data.payload)); return 0; //indicate acceptance of payload for reliable push } catch (err) { alert(err); } } function onSimChange() { //var resultDiv = document.getElementById("resultDiv"); //resultDiv.innerHTML += "<br>" + "SIM card is changed!"; alert("SIM card is changed!"); } // END push notifications
08-09-2012 02:24 PM
I don't see anything wrong with the code you posted.
When are you calling the openBISPushListener() function? I would recommend you call it in the onload of your application's main page:
<body id="mainBody" onload="...">
Also, just want to double check you have the appropriate setup in your application's config.xml:
<feature id="blackberry.push" required="true" version="1.0.0.0"/>
...
<access subdomains="true" uri="*"/>
...
<rim:connection>
<id>BIS-B</id>
<id>MDS</id>
<id>TCP_WIFI</id>
<id>TCP_CELLULAR</id>
<id>WAP2</id>
<id>WAP</id>
</rim:connection>
08-17-2012 05:56 AM
marco, thanks for your help!
I managed to go a bit further... I now get the alert "success" when i open the application, but I send a push from the push-sample-initiator app and the alert on the onData does not show up.
I am calling the openBISPushListener() on the onload of body.