This guide applied to all environments that are compatible with the plugin phonegap-push-plugin (cordova/ionic/phonegap cli/phonegap online build/etc…) and explains how to enable an application for android, ios or windows to support push notifications of Puship.
It is a cordova plugin with a single javascript library that uses the famous phonegap-plugin-push. In this way the push-plugin have to be updated only when new features are released. You will not have another plugin to maintain and update and it is always compatible with the new OS versions.
cordova plugin add puship-plugin
phonegap plugin add puship-plugin
ionic cordova plugin add puship-plugin
onDeviceReady: function() { app.receivedEvent('deviceready'); const push = PushNotification.init({ android: { }, browser: { pushServiceURL: 'http://push.api.phonegap.com/v1/push' }, ios: { alert: "true", badge: "true", sound: "true" }, windows: {} }); push.on('registration', (data) => { //alert("registrationid: " + data.registrationId); //CODE TO ADD Puship.Register( data.registrationId, 'YOUR-PUSHIP-APP-CODE', { successCallback: function (pushipresult) { alert("device registered with DeviceId:" + pushipresult.DeviceId()); }, failCallback: function (pushipresult) { alert("error during registration: "+ JSON.stringify(pushipresult)); } } ); }); push.on('notification', (data) => { alert(JSON.stringify(data)); // data.message, // data.title, // data.count, // data.sound, // data.image, // data.additionalData }); push.on('error', (e) => { // e.message }); },
Once the application is running you should be able to see the message “device registered with…”. Now you are able to connect to the Puship Manager and send push notifications to your devices!