Tom Schreck
Tom Schreck

Reputation: 5287

Do you need PhoneGap 3.1 command line tool if you are using PhoneGap Build

I'm trying to get started with developing a PhoneGap app, but am very confused. My development environment is Windows and I'm using VisualStudio to create my app using HTML 5, CSS 3, jQuery, jQuery Mobile, etc. I have a PhoneGap Build account where I'm able to upload a zip file of my application and it builds. I'm using PhoneGap 3.1.0. I'm trying to check my network connection. In my config.xml file, I have the following:

<feature name="NetworkStatus">
    <param name="ios-package" value="CDVConnection" />
</feature>

Here's my code for checking connection:

        // Wait for device API libraries to load
        document.addEventListener("deviceready", onDeviceReady, false);

        // device APIs are available
        function onDeviceReady()
        {
            checkConnection();
        }

        function checkConnection()
        {
            try
            {
                var networkState = navigator.connection.type;

                var states = {};
                states[Connection.UNKNOWN] = 'Unknown connection';
                states[Connection.ETHERNET] = 'Ethernet connection';
                states[Connection.WIFI] = 'WiFi connection';
                states[Connection.CELL_2G] = 'Cell 2G connection';
                states[Connection.CELL_3G] = 'Cell 3G connection';
                states[Connection.CELL_4G] = 'Cell 4G connection';
                states[Connection.CELL] = 'Cell generic connection';
                states[Connection.NONE] = 'No network connection';

                alert('Connection type: ' + states[networkState]);                  
            }
            catch (e)
            {
                alert(e);
            } 
        }

navigator.connection.type errors out and is ALWAYS undefined regardless of my network connection on my iPad mini.

Here are the JavaScript files I'm including:

    <script src="cordova.js"></script>
    <script src="cdv-plugin-fb-connect.js"></script>    
    <script src="facebook-js-sdk.js"></script>

I'm seeing a lot of confusing and contradicting information while googling for a solution.

  1. Do I need to have references to both cordova.js and phonegap.js or one or the other in my Index.html file?
  2. Since I'm developing in Windows, I do not have access to a Mac. Do I need to use a command line tool to establish a project structure? Can I do this manually? I am able to build my app using PhoneGap Build and can install it on my iPad Mini. I just cannot test for a network connection.
  3. Am I suppose to include references to other JavaScript files for network connectivity? If so, where do they exist? I'm assuming since I put NetworkStatus feature in config.xml, that PhoneGap Build will inject the necessary javascript files into my project. Since navigator.connection.type is ALWAYS undefined, I'm assuming I'm missing a file somewhere that contains the code for network status. Where does this exist?

Please help me with a direction. It's my understanding that all I need to do is create my application using HTML 5, CSS, and necessary JavaScript and that all I need for PhoneGap is config.xml file with necessary entries in order to build my application for different platforms using PhoneGap BUild. I should not have to go to a Mac or Eclipse etc for each platform I want to support.

Upvotes: 0

Views: 428

Answers (1)

QuickFix
QuickFix

Reputation: 11721

You do not need the CLI to use phonegap build, all you need is your html5 app and a config.xml configuration file for your project.

Phonegap cli allows to automate remote build but it is not a requirement at all.

  1. You need only to reference phonegap.js in your html file (cordova.js is automatically loaded using require).

  2. With no mac you will be able to build your app but you will need a apple developer account to be able to add certificate to your app and be able to install in your devices (using provisioning profile). But unfortunatly you still need a mac if you want to add your app on the apple store.

  3. I think what you miss is defining plugins in config.xml (in phonegap 3 each core api is a plugin you need to include if you use it). The way you include a plugin in your plugin is not by adding <feature> tag but with <gap:plugin>.

I suggest you have a look at phonegap build docs. And check the plugin list at this page.

For the connection api, you need to add the line

<gap:plugin name="org.apache.cordova.network-information" />

4.And finally, to use facebook connect plugin, you shouldn't have to include js files, instead follow instructions on this page to add the plugin.

Edit in answer to comment

At the begining of the doc you lincked, you will see it is instructed to use cordova plugin add org.apache.cordova.network-information to install the plugin, which is the way to proceed when using the CLI.

For phonegap build you have to add the line <gap:plugin name="org.apache.cordova.network-information" /> in config.xml to achieve the same result. Check the plugin doc on phonegap build for proper instructions.

About the <feature> lines, what's actually explained in the doc, is that when you use the CLI to install the plugin, the lines <feature name="NetworkStatus">... are automatically added in the file platforms\android\res\xml\config.xml (and that has to be done manually for people building locally and not using the CLI)

The key is this sentence :

These commands apply to all targeted platforms, but modify the platform-specific configuration settings described below:

Upvotes: 2

Related Questions