This guide shows how to make a Cordova/PhoneGap application (android, iOS and windows phone) supporting Puship push notifications through the Command Line Interface platform.
Before creating the application, it is necessary to have configured correctly the CLI with the SDK of the platforms that have to be supported (a guide for cordova at this link, for phonegap at this link). Otherwise you can use the online build following the guide present on the PhoneGap Online Build page
cordova create puship com.puship.example Puship //The first parameter (puship) defines the project folder name //The second parameter (com.puship.example) defines the project package //The third parameter (Puship) defines the Application’s name
cordova plugin add puship-plugin
onDeviceReady: function() { this.receivedEvent('deviceready'); push = PushNotification.init({ android: { }, browser: { pushServiceURL: 'http://push.api.phonegap.com/v1/push' }, ios: { alert: 'true', badge: 'true', sound: 'true' }, windows: {}20 }); push.on('registration', (data) => { Puship.Register(data.registrationId, 'YOUR-PUSHIP-APP-CODE'); }); push.on('notification', (data) => { alert(JSON.stringify(data)); // data.message, // data.title, // data.count, // data.sound, // data.image, // data.additionalData }); push.on('error', (e) => { alert(e.message); }); }
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com https://cloudapp.puship.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; img-src 'self' data: content:;">
cordova platform add android //The platform parameter can be android or ios
cordova build
Once the application is running you should be able to see the “device registered”. Now you are able to connect to the Puship Manager and send push notification to your devices!
Pay attention:
Below it’s available a video that explains how to create an application and activate push notifications with Puship
Download a complete example using the link below to better understand the whole process
Adding tags, geolocations management and all the other api are described in the guide common to all the platform that can be consulted at the following link: