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
Trusted Contributor
chicoxml
Posts: 227
Registered: ‎09-03-2010
My Device: Not Specified

Problem to subscribe to the server push

 

Hi guys,

The Following code not does work, please let me know the possible Problems and What You Should Take steps before.

Thanks
<script>
  var port = ####; // This is the port that I assign rim. I'm doing this wrong?
  function doMySubscription()
  {
     //See if they have a BIS transport.. if so use it
     var transports = blackberry.system.getTransportList();
     found = false;
     for (var i = 0; i < transports.length; i++)
     {
         if (transports[i].name == "BIS")
         {
             found = true;
             blackberry.push.openPushListener(handleMyReturnData, port, transport[i]);
             break;
         }
     }
     if (!found)
         blackberry.push.openPushListener(handleMyReturnData, port);
  }
  function handleMyReturnData(data)
  {
      if (data != null)
      {
         var myRecievedData= blackberry.utils.blobToString(data.payload)
         alert(myRecievedData);
      else
         alert("No data from the push");
  }
  function cancelSubscription()
  {
      blackberry.push.closePushListener(port);
  }
</script>

Please use plain text.
New Member
ChevrollBryan
Posts: 1
Registered: ‎07-18-2009
My Device: Not Specified

Re: Problem to subscribe to the server push

This API, blackberry.push.openPushListener, is deprecated, it's advised to now use blackberry.push.openBESPushListener or blackberry.push.openBISPushListener instead.

 

Hope the code snippet bellow is useful to you.

 

  var port = 876; 
  var appId = "my-app-id";
  var url = "http://pushapi.eval.blackberry.com";

  function openPushListener() {
    //Check if they have a BIS transport.. if so use it
    var transports = blackberry.system.getTransportList();
    found = false;
    for (var i = 0; i < transports.length; i++) {
      if (transports[i].name == "BIS") {
        found = true;
        blackberry.push.openBISPushListener(port, appId, url, handlePushData, handleRegistration, handSimChange);
        break;
      }
    }
    if (!found)
      blackberry.push.openBESPushListener(port, handPushData, handleSimChange);
  }

  function handleRegistration(result) {
    if ( result != 0 ) {
      alert('Registration failed, reason:' + result);
    }
  }
  
  function handleSimChange() {
    if ( confirm.register("SIM card is changed, re-register?") ) {
        openPushListener();
    }  
  }
  
  function handlePushData(data) {
    if (data != null) {
      var myRecievedData= blackberry.utils.blobToString(data.payload)
      alert(myRecievedData);
    }
    else
      alert("No data from the push");
  }

  function cancelSubscription() {
    blackberry.push.closePushListener(port);
  }

 

 

Please use plain text.