Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

BlackBerry Push Development

Reply
Contributor
sergiop
Posts: 23
Registered: ‎04-13-2012
My Device: Curve 9300 OS6

Push notifications in Webworks app

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

Contributor
sergiop
Posts: 23
Registered: ‎04-13-2012
My Device: Curve 9300 OS6

Re: Push notifications in Webworks app

I'm still in trouble getting this to work, does anyone know how to make this work?

 

I'd really appreciate some help!

Retired
marco_dicesare
Posts: 76
Registered: ‎08-08-2012
My Device: BlackBerry Z10

Re: Push notifications in Webworks app

Can you clarify if you are trying to develop a push app for BBOS or for BB10?

Contributor
sergiop
Posts: 23
Registered: ‎04-13-2012
My Device: Curve 9300 OS6

Re: Push notifications in Webworks app

Hi marco,

 

I'm devoloping for BBOS 6 & 7

Retired
marco_dicesare
Posts: 76
Registered: ‎08-08-2012
My Device: BlackBerry Z10

Re: Push notifications in Webworks app

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?

Contributor
sergiop
Posts: 23
Registered: ‎04-13-2012
My Device: Curve 9300 OS6

Re: Push notifications in Webworks app

Ok, so I was following the directions pointed at https://developer.blackberry.com/html5/apis/blackberry.push.html, and got my sample push server working from the BB samples, but didn't receive anything on the phone. I got the java sample demos working on the phone too. I'm not sure how can I debug this, because the functions are simply not being called nor there is an error being thrown.

Retired
marco_dicesare
Posts: 76
Registered: ‎08-08-2012
My Device: BlackBerry Z10

Re: Push notifications in Webworks app

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?

Contributor
sergiop
Posts: 23
Registered: ‎04-13-2012
My Device: Curve 9300 OS6

Re: Push notifications in Webworks app

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

 

Retired
marco_dicesare
Posts: 76
Registered: ‎08-08-2012
My Device: BlackBerry Z10

Re: Push notifications in Webworks app

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>

 

Contributor
sergiop
Posts: 23
Registered: ‎04-13-2012
My Device: Curve 9300 OS6

Re: Push notifications in Webworks app

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.