PhoneGap Build

Integrating Pushwoosh SDK into your PhoneGap Build project

Supports iOS, Android, Windows Phone

Download Sample
Plugin API Docs

To add Pushwoosh plugin to your PhoneGap Build project:

1. Add the plugin in www/config.xml:

<gap:plugin name="pushwoosh-pgb-plugin" source="npm" />

2. In www/config.xml allow access to *.pushwoosh.com:

<access origin="*"/> <!-- allow all pages, use for development -->
<access origin="*.pushwoosh.com"/> <!-- allow pushwoosh service -->

3. In www/config.xml use gradle build tool:

<preference name="android-build-tool" value="gradle" />

4. Add Pushwoosh initialization function to your javascript file:

Important

Do not forget to put the correct Pushwoosh App ID.
For Android put the correct Google Project Number as well.

function initPushwoosh() {
  var pushwoosh = cordova.require("pushwoosh-cordova-plugin.PushNotification");

  // Should be called before pushwoosh.onDeviceReady
  document.addEventListener('push-notification', function(event) {
    var notification = event.notification;
    // handle push open here
  });
  
  // Initialize Pushwoosh. This will trigger all pending push notifications on start.
  pushwoosh.onDeviceReady({
    appid: "PUSHWOOSH_APP_ID",
    projectid: "GOOGLE_PROJECT_NUMBER",
    serviceName: "MPNS_SERVICE_NAME"
  });
}

In onDeviceReady function add initPushwoosh();

Example:

bindEvents: function() {
        document.addEventListener('deviceready', this.onDeviceReady, false);
    },
    // deviceready Event Handler
    //
    // 'this' covers the event. To call 'receivedEvent' function, explicitly call 'app.receivedEvent(...);'
    onDeviceReady: function() {
        app.receivedEvent('deviceready');
        initPushwoosh();
    },

5. Registering and handling push notifications

To register for push notifications call

pushwoosh.registerDevice(
  function(status) {
    var pushToken = status.pushToken;
      // handle successful registration here
  },
  function(status) {
    // handle registration error here
  }
);

For handling notificatios see the following snippet of code in initPushwoosh function

// should be called before pushwoosh.onDeviceReady
document.addEventListener('push-notification', function(event) {
  var notification = event.notification;
  // handle push open here
});

PhoneGap Build

Integrating Pushwoosh SDK into your PhoneGap Build project