Book Image

PhoneGap 3.x Mobile Application Development HOTSHOT

By : Kerri Shotts
Book Image

PhoneGap 3.x Mobile Application Development HOTSHOT

By: Kerri Shotts

Overview of this book

<p>PhoneGap allows you to use your existing knowledge of HTML, CSS, and JavaScript to create useful and exciting mobile applications.<br /><br />This book will present you with 12 exciting projects that will introduce you to the dynamic world of app development in PhoneGap. Starting with their design and following through to their completion, you will develop real-world mobile applications. Each app uses a combination of core PhoneGap technologies, plugins, and various frameworks covering the necessary concepts you can use to create many more great apps for mobile devices.</p>
Table of Contents (21 chapters)
PhoneGap 3.x Mobile Application Development HOTSHOT
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Deploying your project to a simulator/device


Once you've built a project, the next logical step is to actually test it. To do this, you can deploy the code to a simulator (which is handy for debugging on your machine) or deploy the code to a device (which is a must to get a feel for how the app performs on a real device). You can do both using either CLIs, depending upon what the platform SDK supports. (For example, some platform SDKs may only support deploying to a simulator.)

Getting ready

If you need to deploy to the iOS simulator, you may need to install programs called ios-sim and ios-deploy.

To install both, just use the following commands from your command-line or terminal (wait for the first to complete before attempting the second):

sudo npm install -g ios-sim
sudo npm install -g ios-deploy

Getting on with it

Both CLIs can deploy your code to a device or simulator. If you need to test on iOS, keep in mind that iOS only permits deploying to the simulator as of Cordova 3.1. If you need to test on Android, it will normally depend on whether or not you have a device plugged in with USB debugging enabled and whether you are deploying the app to the simulator or a device.

Deploying using the Cordova CLI

The simplest method is to use the following pattern:

cordova emulate platform

To test on the Android simulator, you can type this:

cordova emulate android

To test on the iOS simulator, you can type this:

cordova emulate ios

Both options should launch the respective simulators and then launch the app. If you need to launch in a specific simulator, it's best to open the simulator manually and then deploy to the simulator.

You'll know things are working properly when you can see the app in the simulator. It should look something like this:

Note

The Device is Ready indicator should pulse on the simulator or device.

If you want to deploy to your Android device, plug it in first and then type the following command:

cordova run android

Wait a few moments and your device should begin running the app.

Deploying using the PhoneGap CLI

To deploy using the PhoneGap CLI, it's important to remember that this only works for local builds. If you built remotely, you need to navigate to http://build.phonegap.com and install from there.

To deploy to the iOS simulator, type this:

phonegap local install ios

To deploy to your Android device (be sure to plug it in) or simulator, type this:

phonegap local install android

You should see output similar to the following:

[phonegap] trying to install app onto device
[phonegap] no device was found
[phonegap] trying to install app onto emulator
[phonegap] successfully installed onto emulator

If everything goes as it should, you should see the following image:

Note

The Device is Ready indicator should pulse on the simulator or device.

What did we do?

In this task, we deployed the app to a simulator or your device using the Cordova CLI and the PhoneGap CLI.

It's also important to note that as of Cordova 3.1, deploying directly to your iOS device (as in cordova run ios) is not supported.