Links

PhoneGap Build

How to integrate Pushwoosh SDK into PhoneGap Build project

Supports iOS and Android

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. Get the google-services.json from your Firebase console as described here and add it to your project.
4. Add the following section to your config.xml:
<platform name="android">
<resource-file src="google-services.json" target="app/google-services.json" />
...
</platform>
5. In www/config.xml use gradle build tool:
<preference name="android-build-tool" value="gradle" />
6. 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: "FCM_SENDER_ID",
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();
},
7. 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 notifications 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
});

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.