PhoneGap Build
How to integrate Pushwoosh SDK into PhoneGap Build project

Supports iOS, Android, Windows Phone

To add Pushwoosh plugin to your PhoneGap Build project:
1. Add the plugin in www/config.xml:
1
<gap:plugin name="pushwoosh-pgb-plugin" source="npm" />
Copied!
2. In www/config.xml allow access to *.pushwoosh.com:
1
<access origin="*"/> <!-- allow all pages, use for development -->
2
<access origin="*.pushwoosh.com"/> <!-- allow pushwoosh service -->
Copied!
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:
1
<platform name="android">
2
<resource-file src="google-services.json" target="app/google-services.json" />
3
...
4
</platform>
Copied!
5. In www/config.xml use gradle build tool:
1
<preference name="android-build-tool" value="gradle" />
Copied!
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.
1
function initPushwoosh() {
2
var pushwoosh = cordova.require("pushwoosh-cordova-plugin.PushNotification");
3
4
// Should be called before pushwoosh.onDeviceReady
5
document.addEventListener('push-notification', function(event) {
6
var notification = event.notification;
7
// handle push open here
8
});
9
10
// Initialize Pushwoosh. This will trigger all pending push notifications on start.
11
pushwoosh.onDeviceReady({
12
appid: "PUSHWOOSH_APP_ID",
13
projectid: "FCM_SENDER_ID",
14
serviceName: "MPNS_SERVICE_NAME"
15
});
16
}
Copied!
In onDeviceReady function add initPushwoosh();
Example:
1
bindEvents: function() {
2
document.addEventListener('deviceready', this.onDeviceReady, false);
3
},
4
// deviceready Event Handler
5
//
6
// 'this' covers the event. To call 'receivedEvent' function, explicitly call 'app.receivedEvent(...);'
7
onDeviceReady: function() {
8
app.receivedEvent('deviceready');
9
initPushwoosh();
10
},
Copied!
7. Registering and handling push notifications
To register for push notifications call
1
pushwoosh.registerDevice(
2
function(status) {
3
var pushToken = status.pushToken;
4
// handle successful registration here
5
},
6
function(status) {
7
// handle registration error here
8
}
9
);
Copied!
For handling notifications see the following snippet of code in initPushwoosh function
1
// should be called before pushwoosh.onDeviceReady
2
document.addEventListener('push-notification', function(event) {
3
var notification = event.notification;
4
// handle push open here
5
});
Copied!

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.