This guide shows how to make a Cordova application (android, iOS and windows) supporting Puship push notifications through the Cordova 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).
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() { 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.EnableLog(true); 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 }); },
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 with…”. Now you are able to connect to the Puship Manager and send push notification to your devices!
Pay attention:
Below are two videos that explain step by step how to create an application and activate push notifications with Puship for Android and for iOS:
Below there is an example of a project already configured. In that project there are various examples of how to using the Puship method. If you prefer you can just clone it and start from this one
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