Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
PhoneGap By Example

You're reading from   PhoneGap By Example Use PhoneGap to apply web development skills and learn variety of cross-platform mobile applications

Arrow left icon
Product type Paperback
Published in Aug 2015
Publisher
ISBN-13 9781785285318
Length 368 pages
Edition 1st Edition
Languages
Arrow right icon
Toc

Table of Contents (12) Chapters Close

Preface 1. Installing and Configuring PhoneGap FREE CHAPTER 2. Setting Up a Project Structure with Sencha Touch 3. Easy Work with Device – Your First PhoneGap Application "Travelly" 4. Integrating the Travelly Application with Custom Service 5. Crazy Bubbles - Your First HTML5 Mobile Game 6. Share Your Crazy Bubbles Game Result on Social Networks 7. Building a Real-time Communication Application – Pumpidu 8. Building "Imaginary" – An Application with Instagram-like Image Filters 9. Testing the PhoneGap Application 10. Releasing and Maintaining the Application Index

The iOS setup

In order to be able to run the application being developed in an iOS simulator or on an iOS device connected to our computer, we need the following components:

  • OS: Mac OS X
  • IDE: Xcode (6.0 and newer)
  • iOS SDK

The only disappointment when developing for iOS with the ability to debug on your computer is a limitation of the operating system by Apple. Unfortunately, it must only be Mac OS X operating system that does this. If you do not want the ability to run applications on your computer, you can simply use the service PhoneGap Build. However, as we try to better understand the features of PhoneGap, we should look deeper into platform-specific aspects.

We can test many of the Cordova features using the iOS emulator installed with the iOS SDK and Xcode, but we need an actual device to fully test all of the app's device features before submitting it to the App Store. To install apps onto a device, we should be a member of Apple's iOS Developer Program, which costs $ 99 per year. Next, we will describe how to run our application in an iOS emulator, which does not require the acquisition of the program.

So, let's say, we already have Mac OS X installed. The next thing we need to do is install Xcode. It is very simple. Follow these steps:

  1. By keyword "Xcode", find the application in the App Store and press the Install App button. Once Xcode is installed, several command-line tools need to be enabled for Cordova to run.
  2. From the Xcode menu, select Preferences.
  3. Then, click on the Downloads tab.
  4. From the Components panel, press the Install button next to the command-line tools listing.
  5. On the same window, you can install other components, such as several versions of an iOS simulator.

Now, with the help of the Cordova CLI, we can add our future version of iOS applications:

$ cd travelly
$ cordova platform add ios
Creating ios project...

Now, in the platform folder, the ios subfolder appeared, and in the plugins folder, the ios.json file appeared. Let's open travelly/platforms/ios/Travelly.xcodeproj in Xcode.

The Xcode window should look as follows:

The iOS setup

Running the application in the iOS emulator

Now, let's run our application in the iOS emulator using the following steps:

  1. Select the intended device from the toolbar's Scheme menu, such as the iPhone 6, as highlighted here:
    Running the application in the iOS emulator
  2. Press the Run button that appears in the same toolbar to the left of Scheme. This button builds, deploys, and runs the application in the emulator. A separate emulator application opens to display the app:
    Running the application in the iOS emulator

A similar procedure can be done with the help of the Cordova CLI:

$ cordova build ios

This generates ios platform-specific code within the project's platforms subdirectory.

The cordova build command is a shorthand for the following command:

    $ cordova prepare ios
    $ cordova compile ios

To run our application in the iOS emulator, it is enough to execute the following command:

$ cordova emulate ios

We will see the same application in the emulator that we saw when run from Xcode.

You have been reading a chapter from
PhoneGap By Example
Published in: Aug 2015
Publisher:
ISBN-13: 9781785285318
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image