All Platforms

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.

What is the Puship plugin

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.

Configuration

  1. Install and configure the cordova-plugin-push using these guides: installationexamples. (you must be able to run the application causing the triggering of the event push.on(‘registration’))
  2. Depending on the environment in which you are developing, add the push-plugin with the relative mode:

cordova plugin add puship-plugin

phonegap plugin add puship-plugin

ionic cordova plugin add puship-plugin

  1. Add lines from 22 to 33 to the js/index, js file
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
    });
},
  1. Follow the guide at this link to create a new application in the Puship Manager and get the Puship App ID. Replace the value “YOUR-PUSHIP-APP-CODE” with it in the code above.
  2. Activate the needed notification service following the guide relative to the platform you are working on (Apple, Google Play or Microsoft Store).
  3. Run the application

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!