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

Web and WebWorks Development

Reply
Contributor
PabloBB89
Posts: 13
Registered: ‎11-27-2012
My Carrier: Vodafone

Help needed for getting push notifications work with Urban Airship.

[ Edited ]

I have a webworks app and I would like to receive push notifications from urbanairship as I do for android and iphone.

 

But I don´t know how to do it since there are not any documentation. I hope you could help.

 

I don't know if in server URL I should put:  "https:go.urbanairship.com/api/push"  or the push api of bb

 

I have the <feature id="blackberry.push" /> in  config.xml

 

And I have this JavaScript code:

 

Do I need anything else?

 

 

function openBISPushListener(){
	var port = 31892; //the port that blackberry gave me
	var serverUrl = "http://pushapi.eval.blackberry.com";
	var appId = "xxxx"; //the apid that blackberry gave me.
	var max = 100;
	var wakeUpPage = "index.html";
  try {
    var ops = {port : port, appId : appId, serverUrl : serverUrl, wakeUpPage : wakeUpPage, maxQueueCap : max};
    blackberry.push.openBISPushListener(ops, onData, onRegister, onSimChange);
  }
  catch (err) {
    alert(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 += "Resultado";
    resultDiv.innerHTML += "<br>" + 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!";
}

 

Thank you in advance!

 

Please use plain text.
BlackBerry Development Advisor (Retired)
mdandrea
Posts: 311
Registered: ‎08-08-2012
My Carrier: Rogers

Re: Help needed for getting push notifications work with Urban Airship.

Hi,

 

There is documentation available, but before I can point you in the right direction, are you developing for BlackBerry 10 or an older version of the OS?

 

Thanks,

 

Matt

Please use plain text.
Contributor
PabloBB89
Posts: 13
Registered: ‎11-27-2012
My Carrier: Vodafone

Re: Help needed for getting push notifications work with Urban Airship.

Old version

Please use plain text.
BlackBerry Development Advisor (Retired)
mdandrea
Posts: 311
Registered: ‎08-08-2012
My Carrier: Rogers

Re: Help needed for getting push notifications work with Urban Airship.

Have you looked at the descriptions of the arguments and callbacks needed from the API reference for push?

(** these are different from the BlackBerry 10 push APIs **)

https://developer.blackberry.com/html5/apis/blackberry.push.html

 

The server URL is the URL that you were sent when you registered to use push.

It should be of the form: 

http://cp{cpid}.pushapi.eval.blackberry.com

Replace {cpid} with your content provider ID.

Please use plain text.
BlackBerry Development Advisor (Retired)
mdandrea
Posts: 311
Registered: ‎08-08-2012
My Carrier: Rogers

Re: Help needed for getting push notifications work with Urban Airship.

Your sample code looks like it should work to me.  Give it a try and see what happens.  Have you written a Push Initiator?  (an application to send out pushes with)

Please use plain text.
Contributor
PabloBB89
Posts: 13
Registered: ‎11-27-2012
My Carrier: Vodafone

Re: Help needed for getting push notifications work with Urban Airship.

But I´m interested in use urban airship as the push initiator as I do for Android and IOS.

 

UA with the ID sends push to the app. But I think I have to register in some way. There is documentation for bb native app but not for webworks.

 

 

Please use plain text.
BlackBerry Development Advisor (Retired)
mdandrea
Posts: 311
Registered: ‎08-08-2012
My Carrier: Rogers

Re: Help needed for getting push notifications work with Urban Airship.

The API reference I linked to is pretty good at describing what functions need to be called.  Is there anything specific about the blackberry.push.openBISPushListener function that you're unclear about?

 

To be able to send pushes to a BlackBerry, you need to implement a Push Initiator that sends messages using PAP XML.  We have a Push Service SDK you can use to help with this:

https://developer.blackberry.com/devzone/develop/platform_services/push_overview.html

 

Let me know if you have any questions.

 

Thanks,

 

Matt

Please use plain text.