HTML5 Webworks

HTML 5 / Webworks Integration Guide

Download Script
Sample Project

Integrating Pushwoosh into your BlackBerry Phonegap / HTML5 Webworks app is quick and easy! Just do the following steps:

1. Register for Blackberry Push Notifications here: https://www.blackberry.com/profile/?eventId=8121

Enter: http://pushapi.eval.blackberry.com as serverUrl of evaluation server in your client app (no slash at the end!)
In Pushwoosh app config enter: https://pushapi.eval.blackberry.com

2. Download pushwoosh.js script from https://github.com/Pushwoosh/pushwoosh-blackberry-sdk/tree/master/Blackberry5-7-HTML and place it in your project folder. Change YOUR_PUSHWOOSH_APP_ID in your Pushwoosh Application ID script from the control panel.

3. Add the pushwoosh script to index.html before your master script file. Replace ‘YOUR_PUSHWOOSH_APP_ID’ with your Pushwoosh Application ID. You will also need jquery.js. For example:

<script src="http://code.jquery.com/jquery-1.8.2.min.js" type="text/javascript"></script>
<script src="pushwoosh.js" type="text/javascript"></script>
PushWoosh.appCode = 'YOUR_PUSHWOOSH_APP_ID';
 
<script src="master.js" type="text/javascript"></script>

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

function onDeviceReady() {
    //OTHER CODE
    openBISPushListener();
}

5. In your master javascript file add the following code:

var 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) {
        PushWoosh.register(function(data) {
                    alert("PushWoosh register success: " + JSON.stringify(data));
                }, function(errorregistration) {
                    alert("Couldn't register with PushWoosh" +  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! You are ready to receive push notifications for your BlackBerry HTML5 Webworks application!

The server sends notifications as JSON payload in the following format:

{
   m:'the message itself',
   h: 42, // html page id ex: https://cp.pushwoosh.com/content/42
   u: '{key: value}',   //user data
   l: 'http://google.com'   //app redirect link
}

HTML5 Webworks

HTML 5 / Webworks Integration Guide