Adobeâs PhoneGap is now the de facto hybrid technology platform to kick-start your native app creation process. The secret to PhoneGap is HTML5. In this chapter you will be introduced to cross-platform app development with PhoneGap and learn how you can leverage HTML5 to create solutions.
Building Apps with PhoneGap
Do you want to build an app? Of course you do. Everyone does. Apps are the next cool technology, and we all want to play with the cool technology.
Figure 4.1: Adobeâs PhoneGap is a cross-platform mobile OS framework you can use to build native apps.
There is a roadblock when it comes to creating mobile apps: too many new technologies. For instance, iPhone and iPad apps are developed with Objective-C, Android apps are developed with Java and C++, Windows 8 apps are developed using C#. The list of technologies you need to learn today as a developer is staggering.
So how do you make the process of creating apps much easier? You look to forward-thinking technologies and bet hard they will work.
PhoneGap is a framework that is looking to reduce the level of complexity we currently see in mobile app development through leveraging HTML5 as a cross-platform development language. The key to PhoneGapâs success is that you can build your entire solution using Web technologies you are already familiar withâHTML, CSS3, JavaScript, SVG, and Canvasâwithout having to learn complex platform-specific technologies.
Figure 4.2: Use HTML5 to power your apps in PhoneGap.
PhoneGap is an open-source project (now called Cordova, but the term PhoneGap and Cordova are almost interchangeable). You can download the entire code from a GIT repository and build the solution yourself. Adobe is the company that manages the project.
The goal of PhoneGap is to allow you to turn HTML5 apps or micro-sites into native applications. This is done two ways:
- Compiling your PhoneGap app on your development machine
- Leveraging Adobeâs cloud-based PhoneGap build environment
Both solutions give you the opportunity to create apps for ten different platforms. With one set of HTML5 code you can create native apps for the following:
- Android
- iOS
- Windows Phone 7
- Windows Phone 8
- Windows 8
- BlackBerry
- Tizen
- Bada
- Symbian
- WebOS
What is exciting, as you develop solution with PhoneGap, is that you can leverage PhoneGapâs ability to connect to native APIs from the device operating system and, through JavaScript, connect to the Camera, Contacts, Events, GeoLocation, Notification, and many of the features typically reserved for native development.
Figure 4.3: PhoneGapâs website.
Close to one in four hybrid apps is now developed with PhoneGap. It is easy, supports many platforms, and appears to be a silver bullet for rapid cross-platform development. The center of PhoneGap is HTML5.
One Technology to Rule them AllâHTML5
HTML5 is an awesome technology. I know; Iâve written three books on it. I think it rocks!
But here is the secret: it is not that new. At least, it is not as new as the press would have you think. HTML5 is a clever brand tying together a collection of technologies and putting forward a solution stack that can create apps that behave like native desktop solutions.
The core to HTML5 is the following technologies:
- HTML5 Elements
- CSS3
- Video and Audio Elements
- SVG and Canvas
- JavaScript
The core elements of HTML are the tags you see in your page. They include but are not limited to the following elements:
- BODY
- HEAD
- SCRIPT
- HTML
- P
- IMG
You will see the tags displayed on the page in the following format:
<HTML>
<HEAD>
<TITLE>This is a Web Page</TITLE>
</HEAD>
<BODY>
<P>Hello, World</P>
<IMG SRC = âsample.webpâ>
</BODY>
</HTML>
The framework for HTML elements (originally created by Tim Berners-Lee in 1989) was published in 1993 and took the world by storm.
Figure 4.4: A copy of the very first website. We have come a long way in the past 20 years!
But, the original spec was not perfect. Over the next four years, three more iterations of HTML came out, adding in more complexity (notably the inclusion of JavaScript to add client-side interaction), but development of HTML appeared to slow down by the end of the decade. In 2004, a group known as Web Hypertext Application Technology Working Group (WHATWG) began work to bring consistent Web technologies to all. The pioneer of WHATWG is Ian Hickson (who now works at Google). It is through his work and the consolidated work of the team at WHATWG that lesser-known technologies, such as CANVAS, SVG, and CSS3, were brought together and presented as HTML5.
Figure 4.5: The WHATWG started evolving HTML in 2004.
The adoption for HTML5 has been nothing short of amazing. Today, all modern Web browsers support most of the features outlined in the HTML5 specification. This includes Googleâs Chrome, Appleâs Safari, Mozillaâs FireFox, and Microsoftâs Internet Explorer.
What is interesting about HTML5 is that it is not a âcast-in-stoneâ specification. The modular design of the specification is intended to allow emerging technologies to be integrated quickly. For instance, when HTML5 was first published, we did not have smartphones or tablets as we know them today.
To this point, some of the first Web browsers to have the best support for HTML5 are mobile devices such as iPhones, iPads, Android phones, WebOS, and BlackBerry OS. Each of these platforms has technology that allows you to embed a Web browser window into a native app and present HTML pages through it. PhoneGap is leveraging the cross-platform support for HTML5 as a cornerstone in building out sophisticated apps. Where a mobile OS does not support a feature in HTML5, such as a Camera API, then PhoneGap will extend the browser with JavaScript into the native operating system. Clever stuff.
Figure 4.6: HTML5 offers support for mobile browsers.
Today, HTML5 is not limited to just Web browsers on your desktop or mobile device. New implementations of HTML5, through projects such as FireFox OS, Chrome OS, WebOS, and Tizen, are changing HTML5 into the de facto native programming language for the next generation of operating systems.
And, yes, PhoneGap is already working on these forward-thinking HTML5 operating systems.
The Problem Phonegap is SolvingâCross-Platform App Publication
Adobe is set with a big challenge: how to boil the ocean. What do I mean by that? The phrase âboil the oceanâ refers to massively complex projects that tackle massively complex problems.
Normally, when you hear someone say âthat project is boiling the ocean,â it means that the project is being overengineered.
Not the case with PhoneGap.
The challenge Adobe is addressing with PhoneGap is massive: to create a single authoring language common to close to a dozen disparate operating systems. Sun Computer tried it with Java, and it did not work. So why is Adobe trying?
It is the support for HTML5 on all the mobile devices that is making Adobeâs job much easier. Apple, Microsoft, Google, Mozilla, Opera, Oracle, IBM, and many companies are all working to make HTML5 the cross-platform technology of the future.
Phew! Seems like job done, doesnât it? Well, not exactly. While HTML5 is great, it does not address specific features found on native operating systems. A native operating system is generally controlled by a single, private entity and can effectively do what it likes. This is clearly seen with Apple and its iOS platform, used to run iPhones, iPads, iPod Touches, and Apple TV.
To begin with, iOS has three main different user experiences: iPhone/iPod, iPad, and Apple TV. The input mechanism for each is different: single finger, two hands, or a remote control. HTML5 does not fully support gesture controls (e.g., taps, two-finger swipes) and does not support core APIs built into iOS. For instance, iOS has the following APIs available only for native application developers:
- MapKitâfor adding maps to your projects
- GameKitâadding interactive game features such as accomplishments
- iAdâfor including advertising in your apps
- PassbookâAppleâs digital wallet solution
- Notificationsâthose annoying alerts you get on your iPhone
- In-App Purchasesâways to extend your app with additional, paid-for featur...