Skip to content

Integrating Cordova plugin

Download SDK
Download Sample
Plugin API Docs

Note:

iOS Simulator can neither subscribe nor receive push notifications. Android emulator will work.

To integrate Pushwoosh with your Cordova application, follow these simple steps:

1. Install the Plugin source code into your app:

  • For Cordova: cordova plugin add pushwoosh-cordova-plugin
  • For Ionic: ionic plugin add pushwoosh-cordova-plugin
  • For Intel XDK: Add pushwoosh-intel-xdk-plugin as Third-Party Plugin

2. Get the google-services.json from your Firebase console as described here and add it to your project.

3. Add the following section to your config.xml:

<platform name="android">
<resource-file src="google-services.json" target="app/google-services.json" />
...
</platform>

4. Initialize plugin

Add the following function to your javascript file, enter the correct Pushwoosh App ID.
For Android also enter the correct Google Project Number.

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: "YOUR_FCM_SENDER_ID",
serviceName: "MPNS_SERVICE_NAME"
});
}

Call initPushwoosh(); on application start.

Example:

bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent' function, we must 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
});

6. iOS platform


If you use cordova-ios earlier than 4.3.0, enable Push Notifications in Capabilities section in XCode project.

7. Android platform

Check out the latest Google Play services and Android Support libraries using Android SDK Manager.

8. Windows platform

Pushwoosh plugin for windows platform uses WNS. Associate App with the Store in Visual Studio and set Notifications->Toast Capable;
Please note that all UWP apps (Windows 10 and higher) are by default capable of sending toast notifications, without the need to declare such capability.

Share your feedback with us

Your feedback helps us create a better experience, so we would love to hear from you if you have any issues during the SDK integration process. If you face any difficulties, please do not hesitate to share your thoughts with us via this form.