Phonegap Online Build

New Project

The following guide show how to install and run a project that has been already configured to use the push notifications.

  1. Register a new account on build.phonegap.com
  2. Once logged-in the project can be uploaded from github.com github.com or straight from the desktop.
    • To use github, just log-in to github.com and fork the Phonegap Puship Start project, than paste the URL of the freshly created project in the open-source tab
    • To keep the source code on a local environment, download the zip archive containing the template project from this link and upload it in the private tab
  3. Create now a new application in the Puship Manager to get the Puship App ID and replace the value “puship_id” with it in the js/index.
  4. Activate the needed notification service following the guide relative to the platform you are working on (Apple, Google Play or Microsoft Store). Note that if you are using Google Play, you will have to modify the js/index.js file, setting the senderID in the GCMCode
  5. Modify the project package in www/config.xml and include the row access origin to enable the access to the Puship server:
      <widget 
      	xmlns="http://www.w3.org/ns/widgets" 
      	xmlns:gap="http://phonegap.com/ns/1.0" 
      	id="com.puship.example" 
      	version="1.0.0"> <!-- Modify here the package -->
      ...
      <access origin="https://cloudapp.puship.com" /> <!-- Add the following line after the origin -->
  6. Upload once again the zip archive or synchronize the project with github depending on which mode you’ve chosen in the 2nd step.
  7. If you are developing for iOS, you have to insert the developer’s certificate, watch the video at bottom of page that explains how to create it.
  8. Scan the barcode with your smartphone to download the application on your device then run it.

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!

 

Existing Project

The push notifications support can be added to an existing project following these steps:

  1. Add the following code in the receivedEvent method present in the js/index.js file:
      var Puship = window.plugins.puship;
      Puship.EnableLog = true;
      Puship.PushipAppId = puship_id; // I.E.: puship_id = "h1mCVGaP9dtGnwG"
      
      if (Puship.Common.GetCurrentOs()==Puship.OS.ANDROID){
      	var GCMCode = your_sender_id; // This is the senderID provided by Google. I.E.: "28654934133"
      	Puship.GCM.Register(GCMCode,
      	{
      		successCallback: function (pushipresult){
      			navigator.notification.alert("device registered with DeviceId:" + pushipresult.DeviceId);
      		},
      		failCallback: function (pushipresult){
      			navigator.notification.alert("error during registration: "+ JSON.stringify(pushipresult));
      		}
      	});
      } else if (Puship.Common.GetCurrentOs()==Puship.OS.IOS){
      	Puship.APNS.Register(
      	{
      		successCallback: function (pushipresult){
      			navigator.notification.alert("device registered with DeviceId:" + pushipresult.DeviceId);
      		},
      		failCallback: function (pushipresult){
      			navigator.notification.alert("error during registration: "+ JSON.stringify(pushipresult));
      		}
      	});
      } else if (Puship.Common.GetCurrentOs()==Puship.OS.WP){
      	Puship.WP.Register(
      	{
      		successCallback: function (pushipresult){
      			navigator.notification.alert("device registered with DeviceId:" + pushipresult.DeviceId);
      		},
      		failCallback: function (pushipresult){
      			navigator.notification.alert("error during registration: "+ JSON.stringify(pushipresult));
      		}
      	});
      } else {
      	Console.log("Not supported platform");
      }
  2. Create a new application in the Puship Manager to get the Puship App ID and replace the value “puship_id” with it in the js/index.
  3. Activate the needed notification service following the guide relative to the platform you are working on (Apple, Google Play or Microsoft Store). Note that if you are using Google Play, you will have to modify the js/index.js file, setting the senderID in the GCMCode.
  4. Add the following rows in www/config.xml:
      <gap:plugin name="org.apache.cordova.console" /> <!-- required -->
      <gap:plugin name="org.apache.cordova.device" /> <!-- required -->
      <gap:plugin name="org.apache.cordova.geolocation" /> <!-- needed only if you use geolocalization -->
      <gap:plugin name="org.apache.cordova.dialogs" /> <!-- required -->
      <gap:plugin name="cordova-plugin-puship" source="npm" /> <!-- required -->
      ...
      <access origin="https://cloudapp.puship.com" /> <!-- Add the following line after the origin -->
  5. Upload once again the zip archive or synchronize the project with github depending on which mode you’ve chosen in the 2nd step.
  6. If you are developing for iOS, you have to insert the developer’s certificate, watch the video at bottom of page that explains how to create it.
  7. Scan the barcode with your smartphone to download the application on your device then run it.

Pay attention:

  • Push notifications for Blackberry are not yet supported by the online builder


Below it’s available a video that explains, in the first part, how to create the application with CLI and certificates, in the second part how to apply them to phonegap online build.





Adding tags, geolocations management and all the other api are described in the guide common to all platforms that can be consulted at the following link: