PhoneGap Beginners Guide (third edition) - Purusothaman Ramanujam - E-Book

PhoneGap Beginners Guide (third edition) E-Book

Purusothaman Ramanujam

0,0
35,99 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

This book is for web developers who want to be productive in the mobile market quickly. In fact, by using PhoneGap, it's possible to deploy native applications based on web standards. This book assumes a very small knowledge of HTML/CSS/JavaScript and mobile platforms, such as Android, BlackBerry, iOS, and Windows Phone, and takes the reader step-by-step into a deep overview of PhoneGap and its APIs.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB
MOBI

Seitenzahl: 298

Veröffentlichungsjahr: 2015

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

PhoneGap Beginner's Guide Third Edition
Credits
Foreword
About the Authors
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Sections
Time for action – heading
What just happened?
Pop quiz – heading
Have a go hero – heading
Conventions
Reader feedback
Customer support
Errata
Piracy
Questions
1. Introduction to PhoneGap
About PhoneGap
PhoneGap and Apache Cordova
The evolution of PhoneGap and Cordova
Choosing an operating system for development
Mobile web versus mobile app
Installing dependencies
Java JDK
Apache Ant
Installing PhoneGap
Setting up your development environment
Time for action – setting up Android using PhoneGap 3.x
What just happened?
Working with other platforms
Getting started with Android and JBoss
Time for action – using JBoss Developer Studio
What just happened?
Getting started with iOS and Xcode
Getting started with Windows Phone and Visual Studio
Summary
2. Building Your First PhoneGap Project
The structure of a PhoneGap application
Using the PhoneGap CLI
Cordova events
The deviceready event
The online event
The offline event
The pause event
The resume event
The backbutton event
Time for action – the Hello World example
What just happened?
WebKit debugging – Chrome, Safari, and Opera
Gecko debugging – Firefox
Internet Explorer
Debugging workflow
Building and deployment
Summary
3. Mobile Frameworks
Building native UI for the mobile
The viewport meta tag
Unwanted telephone number linking
Autocorrect
CSS media queries and mobile properties
Screen orientation
Device orientation
Shake gestures
Media capture APIs
Data URI
Achieving a native look and feel on iOS
Choosing mobile frameworks
Using HTML5 Mobile Boilerplate
Using Zurb Foundation
Using Twitter Bootstrap
Ionic framework
ExtJS
AngularJS
jQuery Mobile
Time for action – developing with jQuery Mobile
Selecting a framework
Summary
4. Working with Plugins
An introduction to plugins
Getting started with plugins
Installing plugins
Listing installed plugins
Removing plugins
Using plugins with Plugman
Exploring the Device API
Time for action – accessing the Device API
What just happened?
Custom plugins
Summary
5. Using Device Storage and the Files API
Application data storage
Exploring the PhoneGap LocalStorage API
Time for action – reading and writing data on the LocalStorage
What just happened?
Exploring the PhoneGap SQL storage
Working with database storage in PhoneGap
Time for action – populating a local database
What just happened?
Database limitations
Understanding the Files API
Reading directories and files
Time for action – listing folders
What just happened?
Writing and reading a file's data
Time for action – reading and rendering an image
What just happened?
Transferring files
Time for action – downloading and saving a file
What just happened?
Summary
6. Using the Contacts and Camera APIs
The Contacts API
The ContactName object
The ContactField object
The ContactAddress object
The ContactOrganization object
The Contact object
Filtering contact data
Time for action – searching device contacts
What just happened?
Time for action – adding a new contact
What just happened?
Camera API or Capture API?
Accessing the camera using the Camera API
Time for action – accessing the device camera
What just happened?
Controlling the camera popover
Time for action – controlling the position of the camera roll
What just happened?
The Media Capture API
Time for action – manipulating images with a canvas
Summary
7. Accessing the Device Sensors and Locations API
Introducing device sensors
Sensors and human-computer interaction
Accelerometer
Detecting shakes
Device orientation events
Handling orientation with JavaScript
Time for action – handling device orientation with JavaScript
What just happened?
Compass
Creating a compass
Time for action – using the Compass API
What just happened?
An introduction to geolocation
The PhoneGap Geolocation API
Time for action – showing device position with Google Maps
What just happened?
Other geolocation data
Summary
8. Advanced PhoneGap
Using the Globalization API
Localizing your app
Time for action – rendering localized messages
What just happened?
Adding multitouch gesture support
Time for action – implementing gesture support
Handling click delays
Summary
9. Getting Ready for Release
Exploring JavaScript compression
Google Closure Compiler
Time for action – compressing files using the Closure Compiler
What just happened?
UglifyJS2
Time for action – using UglifyJS
What just happened?
Optimization with RequireJS
Time for action – optimizing JavaScript with RequireJS
What just happened?
Comparing compression tools
Using template engine compression
Time for action – compiling a template using Pistachio
What just happened?
Creating fluid, multiple app views
Using hardware-accelerated transitions
AliceJS
Porting web applications
Summary
10. A Sample PhoneGap Project
What's in the app?
Libraries used
Twitter Bootstrap
jQuery
mMenu
FastClick
Creating the project
Installing plugins
Design of the homepage
Using the Accelerometer API
Using the Device API
Using the Camera API
Using the Capture API
Using the Connection API
Using the Contacts API
Using the Files API
Using the Globalization API
Using the InApp Browser API
Using the Notification API
Using the Splash Screen API
Using the GeoLocation API
Building the app
Scope for improvements
Summary
A. The JavaScript Quick Cheat Sheet
The getElementById() method
The getElementsByTagName() method
The getElementsByName() method
The alert method
The toString() method
The parseInt() method
The getDate() method
The onclick event
The ondblclick event
The window.location object
Selectors using jQuery
B. Publishing Your App
Publishing on Google Play
Publishing on Blackberry World
Publishing on the Apple App Store
Publishing on the Windows Phone Store
Summary
C. Related Plugin Resources
Summary
D. PhoneGap Tools
The PhoneGap Developer App
The PhoneGap Desktop App
Summary
Index

PhoneGap Beginner's Guide Third Edition

PhoneGap Beginner's Guide Third Edition

Copyright © 2015 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

First published: September 2011

Second edition: September 2013

Third edition: July 2015

Production reference: 1220715

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham B3 2PB, UK.

ISBN 978-1-78439-228-4

www.packtpub.com

Credits

Authors

Purusothaman Ramanujam

Giorgio Natili

Reviewers

Ahmad Alrousan

Rafael Reyna Camones

Bhargav Golla

Steve Husting

Johnathan Iannotti

Razi Mahmood

Evan Mullins

Commissioning Editor

Usha Iyer

Acquisition Editor

Nikhil Karkal

Content Development Editor

Parita Khedekar

Technical Editor

Taabish Khan

Copy Editors

Trishya Hajare

Adithi Shetty

Project Coordinator

Suzanne Coutinho

Proofreader

Safis Editing

Indexer

Hemangini Bari

Production Coordinator

Nitesh Thakur

Cover Work

Nitesh Thakur

Foreword

The number of mobile devices and their usage is exploding rapidly across a wide variety of users around the world, heralding a series of very unique opportunities. For businesses, the opportunity to conceptualize new business applications and ideas, prototype, develop, and deliver these new capabilities to the market is very important. Customers benefit by being able to interact with brands and functions that have a direct and materially positive impact on their daily lives.

It sounds easy, but the major challenge today for a business is how to best support a dizzying array of mobile devices that are constantly evolving. Instead of targeting individual devices, such as the iPhone 6 or Samsung Galaxy 4, businesses begin to target device platforms, such as iOS, Android, and Windows Phone. Still, significant challenges remain when trying to quickly deliver powerful mobile application functionalities across multiple platforms.

This is where PhoneGap has such a significant role to play. Put simply, PhoneGap helps businesses develop mobile applications faster for a large variety of devices with minimum cost and time. To be successful, it's incredibly important to analyze the user's requirements upfront and then select the best tool and platform for development. Leveraging the correct APIs and programming models, techniques, and UX patterns can make the difference between a mobile application that is compelling and one that is too hard to use.

Keeping all of this in mind, this book seeks to educate developers on how to develop code in PhoneGap. As written by Purusothaman, I think you will find that this book is quite different from traditional development books. For example, each chapter is appropriately narrated for both the beginner and advanced level users. The examples covered in each chapter are simple and easy to understand but are still thorough enough to deliver important insights and lessons. The examples provided, and especially the sample project at the end, are very useful to PhoneGap programmers.

I would strongly recommend this book to those who want to get started with mobile application development or those who are already developing mobile applications to learn PhoneGap as a cross-platform tool to deliver compelling mobile applications.

Ranga Srinivasan

CTO & President, Ameex Technologies

About the Authors

Purusothaman Ramanujam is a mainframe consultant and an automation expert by profession and a full stack web developer and trainer by passion. He holds a bachelor's degree in information technology and a master's degree in financial management. He has a strong domain knowledge of financial markets. Apart from working full-time at a multinational corporation, he freelances and contributes to various open source projects. In his personal blog at http://www.purusothaman.me, he writes about technology, Tamil poetry, French, and more.

Giorgio Natili is an author, educator, community leader, and lead UI engineer at McGraw Hill Education; he is also a publisher of print and digital information services for the academic, professional, and library markets.

At McGraw Hill, he is involved with multiple client-side teams on cross-platform mobile and web applications, developing custom components (web and native) and bringing mock-ups to life!

Giorgio was also the founder of GNStudio, a boutique Rome-based development and design studio specializing in engaging and accessible web and mobile experiences.

As a strong proponent of agile development practices, Giorgio's areas of expertise include web standards-based application development, frontend development, gaming, video streaming, iOS development using Swift and Objective-C, Android development, and hybrid development (mobile and wearables).

Giorgio is the founder of Mobile Tea (http://www.meetup.com/mobiletea/), a fresh and innovative approach to community tech events, and is involved in several other community-driven events in Italy and the US.

About the Reviewers

Ahmad Alrousan has been a professional developer for many years, specializing in building desktop, web, and mobile software solutions for many sectors.

He holds a bachelor's degree in computer engineering and is a .NET Microsoft Certified Professional Developer (MCPD) and Microsoft Certified Solutions Developer (MCSD).

He spends a lot of time working on software projects and learning new skills. He can be reached at <[email protected]> (e-mail) and http://sa.linkedin.com/pub/ahmad-alrousan/38/758/a8b (LinkedIn).

He has also reviewed Mobile First Design with HTML5 and CSS3, Jason Gonzales, Packt Publishing, which was published in September 2013.

I would like to thank my family, especially mom, for the continuous support they have given me throughout my life. I could not have done it without them.

Rafael Reyna Camones is an information technology consultant. He currently works at IBM as a software developer.

He has experience in the development of modules for Moodle and focuses on the integration of e-learning platforms with mobile devices (iOS, Android, and Windows Phone).

He graduated as a systems engineer from the Universidad Nacional José Faustino Sánchez Carrión. He has trained the university staff in the use of Moodle and has developed a pilot for implementation.

In his spare time, he enjoys a good conversation and exchange of ideas.

Other books reviewed by Rafael are Instant Moodle Quiz Module How-to, Joan Coy, and Best Practices in Moodle Course Design, Susan Smith Nash and Michelle Moore, both published by Packt Publishing.

Bhargav Golla is a master's student in computer science at Clemson University. Before going to Clemson, he graduated from Birla Institute of Technology and Science, Pilani, Pilani campus, with a B.E (Hons.) in computer science and engineering. Being chosen for the Google Summer of Code twice in a row, he had the pleasure of working with the open source organization Apache Software Foundation's projects Isis and PhotArk, where he built cross-platform mobile apps for the two projects. He believes in providing technical solutions to the problems we face. Interning at different tech companies in the past, he is currently looking forward to start his career as a developer.

Steve Husting wears various hats by day, including that of a website worker and product photographer, at a company that designs and manufactures radio-controlled hobby cars. By night, he writes, does calligraphy, and creates iPhone and Android apps. He posts his findings about PhoneGap apps on his blog, http://iphonedevlog.wordpress.com, which is geared up to help beginners get up and running in making cool apps. He also helped provide feedback for PhoneGap 3.x Mobile Application Development Hotshot, Kerri Shotts, Packt Publishing.

Johnathan Iannotti is a software engineer and geek on an epic journey of life. His experience spans 15 years of technology solutions for start-ups, financial companies, healthcare, and military industries. He is passionate about web technology and has been creating hybrid apps since their inception. A full-stack developer by trade, he loves UX/UI, frontend development, and mobile.

He works for USAA, creating mobile applications for over 27,000 employees who serve their military membership. He is also a combat veteran, having served almost a decade in the United States Army.

Johnathan spends his time innovating, coding, and making the best of it all. When he's not plugged in, he spends as much time as he can with his beautiful wife and two children, who make it all possible <3.

Follow Johnathan on Twitter at @notticode or visit his website at www.johnforhire.com.

Razi Mahmood is a software training consultant, currently active in delivering mobile apps development training in Malaysia. He covers Android, iOS, and PhoneGap/Cordova topics. His clients include Malaysian Development Corporation (MDEC), Malaysian Administrative Modernisation and Management Planning Unit (MAMPU), Ministry of Science, Technology and Innovation (MOSTI), Ministry of Finance, Ministry of Defense (MINDEF), Putrajaya Holdings Sdn Bhd, Kuala Lumpur City Hall, Petaling Jaya Municipal Council, Kota Bharu Municipal Council, Taiping Municipal Council, Penang Computer Center KOMTAR, and Kulim High Technology Park. He blogs at www.razi.net.my.

Evan Mullins studied digital media and earned his BFA at the University of Georgia, always interested in both design and technology. While attending, he also studied computer science, animation, and new media. He loves the cross-section of art and technology in which we find the Web.

Professionally, Evan has worked with a slew of start-ups, small businesses, and agencies, building websites such as Cartoon Network, Ogilvy & Mather, Brand Fever, and he is currently the lead web developer at Brown Bag Marketing. He is continually busy designing and developing interesting things online.

Since 2004, Evan has also maintained circlecube studio (https://circlecube.com/) as a freelance web studio and also a playground for open source experiments and examples, as well as to simply share tips he learns along the way. The blog content centers around interactive development principles and technologies. He gives back by sharing what he learns online as well as at conferences.

Evan is happily married and a proud father of four. He enjoys spending time away from work with his real job, his family. He also volunteers for his church and unplugs by camping outside, playing soccer, and/or playing music.

www.PacktPub.com

Support files, eBooks, discount offers, and more

For support files and downloads related to your book, please visit www.PacktPub.com.

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at <[email protected]> for more details.

At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.

https://www2.packtpub.com/books/subscription/packtlib

Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.

Why subscribe?

Fully searchable across every book published by PacktCopy and paste, print, and bookmark contentOn demand and accessible via a web browser

Free access for Packt account holders

If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view 9 entirely free books. Simply use your login credentials for immediate access.

Always in memory of Rajeshwari Ramanujam

Ma,

I miss you every day...

Wish you were here to walk with me...

Smile as I talk about my first love...

Ask me about my day at work…

Wish you were here with us for everything…

I keep wondering every moment…

What you would think and feel about me…

I miss you Ma...

Preface

PhoneGap Beginner's Guide Third Edition will help you break into the world of mobile application development. You will learn how to set up and configure your mobile development environment, implement the most common features of modern mobile apps, and build rich, native-style experiences. All the examples deal with real use case scenarios covering the functionality of various plugins.

What this book covers

Chapter 1, Introduction to PhoneGap, covers how to set up dependencies and mobile platform SDKs in your development environment.

Chapter 2, Building Your First PhoneGap Project, deals with PhoneGap internals, project structure, and using CLI tools.

Chapter 3, Mobile Frameworks, gives an introduction to various mobile frameworks and sample projects using jQuery Mobile.

Chapter 4, Working with Plugins, covers information about PhoneGap plugins and using them in the application.

Chapter 5, Using Device Storage and the Files API, deals with offline data storage capabilities and the Files plugin.

Chapter 6, Using the Contacts and Camera APIs, covers how to implement the Contacts API and how to interact with the device camera by using the Camera API.

Chapter 7, Accessing the Device Sensors and Locations API, deals with using device sensors and the Locations API and their power and limitations with respect to the plugins provided by PhoneGap.

Chapter 8, Advanced PhoneGap, covers some advanced topics such as adding multilanguage and touch gesture support to your application.

Chapter 9, Getting Ready for Release, helps you understand how to make your application ready for public release in various application stores.

Chapter 10, A Sample PhoneGap Project, deals with the development of a full-fledged PhoneGap application from scratch, using the most common PhoneGap plugins.

Appendix A, The JavaScript Quick Cheat Sheet, is a mini cheat sheet for commonly used JavaScript methods and properties.

Appendix B, Publishing Your App, describes how you can publish your apps on different app stores.

Appendix C, Related Plugin Resources, is a list of some related plugins that can be used with PhoneGap.

Appendix D, PhoneGap Tools, describes tools that will help you to debug and test your applications without any difficulties.

What you need for this book

A personal computer with an Internet connection and the default command-line tool to use with the command-line utilities distributed with PhoneGap. OS X and Linux users just need the default command-line tool.

Who this book is for

This book is for web developers who want to be productive in the mobile market quickly. In fact, by using PhoneGap, it's possible to deploy native applications based on web standards. This book assumes a very small knowledge of HTML/CSS/JavaScript and mobile platforms, such as Android, BlackBerry, iOS, and Windows Phone, and takes the reader step-by-step into a deep overview of PhoneGap and its APIs.

Sections

In this book, you will find several headings that appear frequently (Time for action, What just happened?, Pop quiz, and Have a go hero).

To give clear instructions on how to complete a procedure or task, we use these sections as follows:

Time for action – heading

Action 1Action 2Action 3

Instructions often need some extra explanation to ensure they make sense, so they are followed with these sections:

What just happened?

This section explains the working of the tasks or instructions that you have just completed.

You will also find some other learning aids in the book, for example:

Pop quiz – heading

These are short multiple-choice questions intended to help you test your own understanding.

Have a go hero – heading

These are practical challenges that give you ideas to experiment with what you have learned.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail <[email protected]>, and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at <[email protected]> with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at <[email protected]>, and we will do our best to address the problem.

Chapter 1. Introduction to PhoneGap

PhoneGap is a hybrid application framework that enables you to build native applications using HTML and JavaScript. Developers can write code once and deploy their application across multiple mobile operating systems. PhoneGap provides a JavaScript programming interface that allows you to access features related to the operating system with plain JavaScript. This chapter covers information about PhoneGap and setting up your development environment.

In this chapter, we will cover the following topics:

Understanding what PhoneGap is all aboutGet an overview of the history of Apache Cordova/PhoneGapThe evolution of PhoneGap and CordovaLearn the differences between the mobile web and mobile appLearn how to configure your development environment and all the dependenciesLearn how to create a new project using JBoss, Xcode, and Visual Studio

About PhoneGap

PhoneGap, also called Apache Cordova, is an open source hybrid mobile application development framework. It uses standard and well-known web technologies such as HTML, Cascading Style Sheets (CSS), and JavaScript to create cross-platform mobile applications without using native development languages.

If you want to develop a native Android application, you should know APIs related to Java and Android SDK. For an iPhone app, you need to know Objective-C or Apple's new Swift language. Similarly, for all other mobile platforms, you need to know their respective programming languages. The code you write for one platform does not work for another platform. To overcome these difficulties, we now have a hybrid mobile development framework called PhoneGap. The applications that you develop using PhoneGap can be deployed on several other platforms. It's a write-once-deploy-everywhere kind of framework.

The following is the list of mobile platforms currently supported by PhoneGap:

AndroidiOSAmazon FireOSBlackberry 10Firefox OSUbuntuWindows Phone 8Windows 8TizenWindows 7Browser

The framework enables developers to access all the hardware-dependent features using simple JavaScript. Developers will be able to access device contacts, location, files, device information, and much more, with simple functions. Note that a new platform called "browser" is now supported. Sound interesting? It is left up to you to increase your curiosity.

PhoneGap and Apache Cordova

PhoneGap was originally developed by Nitobi and the company was later acquired by Adobe in 2011. After it was acquired, Adobe donated the PhoneGap code base to the Apache Software Foundation (ASF) under the project name Cordova, which is the name of the street in Vancouver where Nitobi's offices were located and where the company created the first version of PhoneGap.

One of the biggest advantages of moving the code base to the ASF is that anyone can easily contribute to the project. Many companies are not only comfortable with the Apache-flavored licenses but already have a Contributor License Agreement with Apache. For developers who are interested in contributing to a vibrant open source project, Apache Cordova is a great opportunity.

PhoneGap is a free and open licensed distribution of Apache Cordova. Picture Cordova as the engine on which PhoneGap and its related services (debug, emulate, and build services) are built. Adobe provides an integrated platform to build applications for multiple platforms with a single click. If you don't want to use Adobe's build features, you have to manually build applications for each mobile platform. Apart from these, for both PhoneGap and Cordova developers, nothing has changed.

Adobe continues to play a major role in the project, investing in its ongoing development, and the company decided to keep the PhoneGap name to describe its own distribution of the Cordova project. Other contributors to the Apache Cordova project include Google, RIM, Microsoft, IBM, Nokia, Intel, and Hewlett-Packard. For more details about Cordova and PhoneGap, refer to the following online resources. They have several useful bits of information and tutorials for a beginner to start with development:

http://cordova.apache.org/http://phonegap.com/

Note

We will be using the terms PhoneGap and Cordova throughout this book and technically both are the same. You can replace Cordova and PhoneGap with each other.

The evolution of PhoneGap and Cordova

PhoneGap has evolved very quickly since January 2012, with multiple releases every year. Apache Cordova uses Semantic Versioning specification (more information is available at http://semver.org). It's a very good practice that tells developers whether a release has major or minor improvements.

Since the 1.4 release, the project has been known as Apache Cordova. This release is generally considered the first stable release of the framework, with a fairly complete and up-to-date documentation. The 1.5 release fixed a long list of bugs, but the initial reaction of the community was not very favorable because the documentation was outdated and some changes to the main files caused broken build issues to apps developed with earlier releases.

The 1.6 release brought some improvements to the plugin architecture, the Camera and Compass APIs, and the project template files. As is often the case with a maturing community, the release was not perfect but there was a significant improvement in the overall quality compared to the previous release. The 1.7 and 1.8 releases were bug fixes and added support for Bada 2.0. The community reaction was also positive because of the speed of the releases. The 1.9 release addressed even more bug fixes and added support for the new features of the iOS and Android platforms.

Apache Cordova 2.x added the following features and support:

The definition of a unique JavaScript file to use across all platforms thanks to the unification of the JavaScript layer of the Cordova application frameworkThe introduction of a command-line tool (CLI) through which common operations, such as project creation, debug, and emulation, could be performed in a standard way (Android, iOS, and BlackBerry)The capability to embed PhoneGap applications into larger native iOS and Android applications using Cordova WebViewSupport for the Windows phone platformThe porting of the Web Inspector Remote (Weinre) to Node.js and the introduction of a node module that facilitates installation using Node package manager (npm)Improved plugin documentationSeveral improvements to the process of creating iOS appsThe standardization of the commands available for each platform (that is, build, run, and so on)

With the 2.x release, Apache Cordova and PhoneGap has become a mature, stable, and powerful tool in the mobile developer's toolkit.

Since the introduction of version 3.0 in September 2013, PhoneGap has used a new plugin architecture to keep the application core small and fast performing. Plugins can be installed and uninstalled using the updated Cordova command line interface (CLI). PhoneGap 3.0 also introduced several new command-line tools; for instance, users can now install PhoneGap easily using npm without downloading ZIP files. Two new APIs, namely InAppBrowser (earlier known as ChildBrowser) and Globalization API were also released with the PhoneGap 3.0 release. They also started discussions about dropping support for webOS, Symbian, Blackberry (BB7 and earlier versions), and Windows Phone 7.

With PhoneGap 3.1.0, basic support for FirefoxOS and Windows 8 were provided along with other bug fixes and platform enhancements. PhoneGap 3.2.0, released in November 2013, was focused on stability and several bug fixes. In December 2013, PhoneGap 3.3.0 was released with support for Android KitKat (v4.4).

With the release of PhoneGap 3.4.0, advanced support for FirefoxOS was added. PhoneGap 3.5.0 is the last version supporting Windows 7. With PhoneGap 3.6.3, commands supported by Cordova were added. There are several new features deployed to PhoneGap with every new release. At the time of authoring this book, we have PhoneGap 5.1.1, which provides advanced support for the PhoneGap Desktop App and Mobile App.

Choosing an operating system for development

PhoneGap plays by the rules. If a vendor releases an SDK for a single operating system only, then you will have to use that OS to build and deploy your applications.

In detail, for each PhoneGap platform:

You can develop Android apps on any of the major desktop operating systems—Windows, Mac OS X, or LinuxYou can develop Symbian Web Runtime apps on any OS but you can only run the simulator from WindowsYou can develop apps for BlackBerry on any of the major desktop operating systems—the SDK can be installed on Windows or Mac OS X (to run the emulator, you need to install the virtual machine distributed with the SDK)The Windows Phone 8 SDK runs on Windows 8 or Windows 8 ProThe iOS SDK requires OS X 10.7 or later (and, according to the OS X EULA, a Mac computer as well)

Note

You can emulate apps in the desktop browser with Ripple (a Chrome extension that is currently incubated in the Apache Software Foundation http://incubator.apache.org/projects/ripple.html) or with the online emulation service available at http://emulate.phonegap.com.

Practically speaking, your best bet for mobile development is to get a Mac and install Windows on a separate partition that you can boot into, or run it in a virtual environment using Parallels or VMWare Fusion. According to Apple's legal terms, you cannot run Mac OS X on non-Apple hardware; if you stick with a Windows PC, you will be able to build for every platform except iOS. However, you can still use OS X by using VirtualBox and running OS X from a Windows PC.

Anyway, with the new CLI utilities, it is getting to be pretty easy to build an app for all major mobile platforms. Mobile developers are well aware of the problems involved in building cross-platform apps; not surprisingly, the http://build.phonegap.com service is starting to become pretty popular due to the fact that it lets the developer use his/her favorite operating system. After registering with this service, it's possible to build a cross-platform app starting from a common code base. You can upload the code base or pull it from a GitHub repository. At the end of this book, I have included a section dealing with the distribution process for mobile applications.

Mobile web versus mobile app

There are lots of discussions that are centered around deciding what kind of development should be done: mobile-responsive websites or a native app. Some popular websites, such as Gmail, have mobile-friendly websites, as well as native apps. To understand this better, let's see what these are:

Responsive websites

Mobile app

Responsive websites work across all kinds of devices, starting from mobile devices to desktop computers. This way of design is often called Responsive Web Design (RWD).

Applications are designed for mobile devices. They are not meant for desktop computers.

Responsive designs provide a better viewing experience to the users on all devices.

A mobile application gives a typical mobile experience with the entire interface designed with mobile devices in mind.

RWD involves some development concepts such as fluid grid, CSS media queries, responsive tables, and images.

Mobile-related design patterns are used.

Responsive sites adapt well to the device's screen size, which makes reading the content easier.