Blackberry - Push Notification Guide
By Technical Support
#26 To integrate Bulkpush into your BlackBerry Phonegap / HTML5 Webworks application you need to do simple following steps:
1. Register for Blackberry Push Notifications here: https://www.blackberry.com/profile/?eventId=8121
2. Download bulkpush.js script from https://github.com/Bulkpush/bulkpush-bl ... ry5-7-HTML and place it in your project folder. Change the YOUR_BULKPUSH_APP_ID in the script to your Bulkpush Application ID from the control panel.
3. Add the bulkpush script to the index.html file before your master script file. Replace ‘YOUR_BULK_PUSH_APP_ID’ with your Bulkpush.

Application ID. You will also need jquery.js. For example:

Code: Select all<script src="http://code.jquery.com/jquery-1.8.2.min.js" <p=""> </p>
  type="text/javascript"></script>
 <script src="bulkpush.js" type="text/javascript"></script>
     Bulkpush.appCode = 'YOUR_BULKPUSH_APP_ID';
 
<script src="master.js" type="text/javascript"></script>


4. In your onDeviceReady function add the call to the openBISPushListener() function:

Code: Select allfunction onDeviceReady() {
   //SOME OTHER CODE
   openBISPushListener();
 }


5. In your master javascript file add the following code:
Code: Select allvar port = THE_PORT_FROM_BB_REGISTRATION;
var serverUrl = "http://pushapi.eval.blackberry.com";
var appId = "APP_ID_FROM_BB_REGISTRATION";
var max = 100;
var wakeUpPage = "push.html";
function openBISPushListener() {
    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) {
        Bulkpush.register(function(data) {
           alert("Bulkpush register success: "
           + JSON.stringify(data));
                }, function(errorregistration) {
              alert("Couldn't register with Bulkpush"
           +  errorregistration);
                });   
    }
    else if (status == 1) {
        alert("push register status network error");
    }
    else if (status == 2) {
        alert("push register status rejected by server");
    }
    else if (status == 3) {
        alert("push register status invalid parameters");
    }
    else if (status == -1) {
        alert("push register status general error");
    }
    else {
        alert("push register status unknown");
    }
}
     
function onData(data) {
    alert("Push notifications received. Data is " + blackberry.
utils.blobToString(data.payload));
    try {
        return 0; //indicate acceptance of payload for reliable push
    }
    catch (err) {
        alert(err);
    }
}
 
function onSimChange() {
    //handle Sim Card change
}

That’s it! Easy, isn’t it? You are ready to receive push notifications for your BlackBerry HTML5 Webworks application!

For evaluation server in your client app enter: http://pushapi.eval.blackberry.com as a serverUrl (without slash at the end)
In Bulkpush app configuration enter: https://pushapi.eval.blackberry.com

The server sends the notification as JSON payload in the following format:
Code: Select all{
  m:'the message itself',
  h: 42, // html page id ex: https://cp.bulkpush.com/content/42
  u: '{key: value}',   //user data
  l: 'http://google.com'   //link to redirect the application to
}