2 Replies Latest reply on May 18, 2016 11:15 PM by markk51876551

    App runs fine Phonegap Desktop funny things once built in cloud

    markk51876551

      Hi all

       

      I did not know how to put this into the title properly. I am by no means a guru on Phonegap or Javascript. I built an app last year around June.

      The app built fine in the cloud last year and is now on the Apple and Google stores and working perfectly.

       

      This year we want to make some updates.

      I have literally sent the same code to the Phonegap cloud service and it builds the apk fine, but the app is now constantly going to the offline page.

      Its not crashing or anything, it must be something with my ajax query that calls a script on our server and if its fine everything goes through otherwise it loads the offline page. The script on our server simply sends the following text back: ONLINE:1463561886

       

      I will past some of the code here. I hope the forums allow for this.

      You can see the offline.html is called if the ajax query does not get a normal response from our server.

       

      Has something changed that i should be changing. Version of jquery must be updated for it to work with how Phonegap cloud packages the app.

       

      I am at a loss.

      If i run it through Phonegap Windows and connect my phone using the Phonegap Developer app on phone it works perfectly.

       

      This is working perfectly in the app on the app stores and worked perfectly when built with previous version of Phonegap cloud.

       

           <script type="text/javascript" src="cordova.js"></script>

              <link href="jquery.mobile-1.3.0.min.css" rel="stylesheet" type="text/css">

              <script src="jquery-1.11.1.min.js" type="text/javascript"></script>

              <script src="jquery.mobile-1.3.0.min.js" type="text/javascript"></script>

              <script type="text/javascript" src="PushNotification.js"></script>

              <script type="text/javascript" charset="utf-8">

       

                  // Wait for device API libraries to load

                  //

                  var fileObject;

                  var netCheck = 1;

                  var pushNotification;

                  document.addEventListener("deviceready", onDeviceReady, false);

                  screen.lockOrientation('portrait');

                  // SCANNER SECTION

                  function init() {

                      document.querySelector("#startScan").addEventListener("touchend", startScan, false);

                      resultDiv = document.querySelector("#results");

                  }

                  $('navList').parent().hide();

                  // device APIs are available

                  function onDeviceReady() {

                      //alert("Here");

                      window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,onFileSystemSuccess, fail);

                      var resultDiv;

                      var url = 'http://******/onlinecheck.cgi';

                      $.ajax({

                          url: url,

                          dataType: 'text',

                          type: 'post',

                          contentType: 'application/x-www-form-urlencoded',

                          data: $(this).serialize(),

                          success: function( data, textStatus, jQxhr ){

                              $('#info_space').html('Loaded 1.3 - Online');

                              document.getElementById("bookCoursesButton").style.display = "block";

                          },

                          error: function( jqXhr, textStatus, errorThrown ){

                              window.open("offline.html", '_self', 'location=yes');

                          }

                      });

      .........

      Plugins being used

      com.phonegap.plugins.barcodescanner

      com.phonegap.plugins.pushplugin

      org.apache.cordova.device

      org.apache.cordova.device-motion

      org.apache.cordova.device-orientation

      org.apache.cordova.dialogs

      org.apache.cordova.file

      org.apache.cordova.file-transfer

      org.apache.cordova.network-information

       

      org.apache.cordova.vibration

       

      Any assistance would be very welcomed.

      Kind regards

       

      Mark

       

      PluginSourceVersionInstalledLatestPlatforms
      com.phonegap.plugins.barcodescanner   pgb2.2.02.2.02.2.0android,ios,winphone
      com.phonegap.plugins.pushplugin   pgb2.4.02.4.02.5.0android,ios,winphone
      org.apache.cordova.device   pgb0.3.00.3.00.3.0android,ios,winphone
      org.apache.cordova.device-motion   pgb0.2.110.2.110.2.11android,ios,winphone
      org.apache.cordova.device-orientation   pgb0.3.110.3.110.3.11android,ios,winphone
      org.apache.cordova.dialogs   pgb0.3.00.3.00.3.0android,ios,winphone
      org.apache.cordova.file   pgb1.3.31.3.31.3.3android,ios,winphone
      org.apache.cordova.file-transfer   pgb0.5.00.5.00.5.0android,ios,winphone
      org.apache.cordova.network-information   pgb0.2.150.2.150.2.15android,ios,winphone
      org.apache.cordova.vibration   pgb0.3.130.3.130.3.13android,ios,winphone
        • 1. Re: App runs fine Phonegap Desktop funny things once built in cloud
          kerrishotts Adobe Community Professional

          Can you share your entire config.xml file? Can you also share which version of PhoneGap and platforms you're building against?

           

          A few thoughts:

           

          - You're using PGB plugins -- you should definitely update to use NPM plugins, which will also get you newer versions as well.

          - You should consider a single-page app architecture rather than redirecting to another page like this, but that's not the immediate issue at hand, so it's just an "FYI"

          - Make sure you add the Whitelist plugin and configure it appropriately. You'll also need to add a Content-Security-Policy. Since you're contacting an external server, you may have to worry about cross-origin resource sharing a bit too (depending on the platform and what web views you're using).

          • 2. Re: App runs fine Phonegap Desktop funny things once built in cloud
            markk51876551 Level 1

            Thank you so much.

             

            I have updated all my addons to npm. This did not fix the problem but nice to know these will be newer versions.

             

            For others that might experience something similar.

            The app now correctly sees that it is online after the following were added.

            config.xml

            <gap:plugin name="cordova-plugin-whitelist" source="npm" />

            <allow-navigation href="*" />

            <access origin="*" /> - this was already in but from what i understand is required.

             

            .html page

            <meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">

             

            again thank you.

            Mark