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
Free Learning
Arrow right icon
Phonegap for Enterprise
Phonegap for Enterprise

Phonegap for Enterprise: Master the art of building secure enterprise mobile applications using PhoneGap

eBook
€8.99 €19.99
Paperback
€24.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Phonegap for Enterprise

Chapter 1. PhoneGap and Enterprise Mobility

The enterprise has always focused on providing solutions that enable its users to access important data in a variety of ways. With smartphones being the norm, the enterprise can leverage the mobility of its users and deliver real-time data in a timely fashion. Of course, the smartphone environment is a quickly changing and rapidly evolving environment; as such, solutions need to be equally agile.

PhoneGap/Cordova is a framework that enables the enterprise to target multiple smartphone platforms with a single code base using technologies the enterprise is already largely familiar with. It's a perfect fit for the enterprise, as it doesn't require duplication of effort to build multiple native applications that must essentially be rewritten for each supported platform. Users like choice in their mobile devices, and PhoneGap/Cordova allows the enterprise to offer just that.

Furthermore, since PhoneGap/Cordova provides developers with access to the native features of the user's mobile device, it also provides the necessary technologies to interact with the enterprise's systems over a variety of networks. This means that users can be highly mobile without losing access to highly valuable and timely enterprise data.

It is this ability of PhoneGap/Cordova to display both content using web-based technologies, and interface with the mobile device using native technologies that gives rise to the term hybrid. This simply means that PhoneGap/Cordova apps are neither purely web-based (as a web app would be), nor are they purely native-based (as a native iOS app would be); they are a blend of the two. This allows PhoneGap/Cordova apps to be written using technologies already established within the enterprise while also allowing immense flexibility.

In this chapter, we'll cover the following sections:

  • Some history behind PhoneGap/Cordova
  • Reasons why it makes perfect sense in an enterprise development
  • How PhoneGap/Cordova enables fast cross-platform development
  • The application structure and the technology stack

    Note

    Throughout this book, we'll often use the term "Cordova" to refer to both PhoneGap and Cordova. PhoneGap is a distribution of Cordova and is very similar to Cordova. Where there are differences, this book will mention them separately by name.

This book assumes that the reader has a good working knowledge of PhoneGap/Cordova from a personal perspective, and is also someone who is now tasked with taking that knowledge into the enterprise. As such, we won't cover the installation of PhoneGap/Cordova, neither will we cover the installation of native platform SDKs.

Why PhoneGap/Cordova?

Cordova is a natural fit for the enterprise environment for many reasons, some of which are listed as follows:

  • Quickly create cross-platform hybrid apps with little duplication of work and high code reuse
  • Leverage technologies already known by most developers familiar with web, multi-tier, and backend development
  • Access native features on mobile hardware—including network information, device location, camera, and more
  • Where necessary, create custom plugins to extend PhoneGap/Cordova for specific needs
  • Embed PhoneGap/Cordova into existing native apps as a component
  • A very active development community (nearly 22,000 members in the Google group for PhoneGap), including a good deal of third-party plugin development (as of this writing, 1,168 plugins are made available by 797 different authors); core development is supported by Adobe (PhoneGap) and Apache (Cordova)
  • Ability to deploy apps internally or to app stores
  • Open source (Apache license)
  • Enterprise-grade support options available
  • Additional features offered for PhoneGap by Adobe for the enterprise (http://enterprise.phonegap.com)

History behind PhoneGap and Cordova

Initially, PhoneGap was owned by Nitobi Software. In earlier versions, it was distributed in the form of project templates that could be used in Xcode or Eclipse to create hybrid apps. While it was easy to develop single-platform apps, it was more difficult to develop cross-platform apps (one had to create copies of the web-specific code and keep those copies synchronized across projects). Even so, many production apps were developed and hosted on app stores, and many more were developed and distributed internally within enterprises.

In 2011, Adobe purchased Nitobi Software. As part of the acquisition, the PhoneGap code was contributed to Apache and made open source. The project was ultimately renamed as Apache Cordova. Adobe kept the PhoneGap name and began maintaining a fork of Apache Cordova's code. As such, the version was changed to 2.x. Generally, the two were largely identical (with only minor variations). Since the project templates of the prior 1.x era were often problematic, the project creation transitioned to a command-line interface (CLI). Cross-platform development was now somewhat easier, though not yet ideal.

Apache Cordova 3.x was released in July 2013. It provided a new CLI that dramatically simplified cross-platform development while also making plugin installation easier and less problematic than before. It also decoupled many of the core features and distributed them as core plugins instead. This allowed developers to pick and choose which plugins they needed rather than taking them out later (which was often difficult). This means that apps written with 3.x only need to ask for the permissions they actually use, whereas under 2.x, an app would often ask for permissions it never needed.

Easy cross-platform development

Since writing a native app will require an app to be rebuilt from scratch for each additional platform, in Cordova, the largest portion of the app is built on web technologies that are inherently cross-platform. Only the native wrapper and native plugins are specific to each particular platform.

In the 1.x version of PhoneGap, the developer was required to compile the project on their own development machine. The developer needed a machine capable of supporting the specific development environment for each of the supported platforms. When 2.x was released, Adobe made it possible to build projects in the cloud, and recently, they also enabled on-device testing with no build requirement at all.

This means that the developer has many different environments that they can use and none of these environments are mutually exclusive (many are used together). The environments are shown in the following diagram:

Easy cross-platform development

Many developers still prefer the local development environment, even though it often requires a good deal of setup and maintenance. The local build environment offers the greatest degree of control because the entire build process takes place on the developer's machine. It's also the most secure: the files and assets remain completely within the enterprise's network unless deploying the app externally.

The PhoneGap build environment allows developers to write their apps on their machine using a text editor and then upload these apps to the cloud for compilation. This means that there is no need to set up and maintain a full development environment—a good text editor is sufficient (though an editor that understands web development is a good idea). There are some platforms that require additional steps before the results can be tested or deployed. However, Apple for example, requires various certificates and provisioning prior to it being tested and deployed on real devices.

Recently, PhoneGap also released the PhoneGap Developer App—this app is downloadable from several app stores and provides one more way to test apps on real devices. The app is itself a PhoneGap app that can connect to your development machine to load HTML, CSS, and JavaScript code. Furthermore, it includes all the core plugins, and if these are all that an app requires, the app can be tested on a physical device without any compilation at all. (Of course, if third-party or custom plugins are necessary, this is no longer entirely possible.) Furthermore, any changes to the code are automatically reflected on the device, eliminating the tedious build and deploy cycle. (This app also works with the Cordova CLI without automatic reloading.) From the security perspective, the app works only on a local network, and unlike PhoneGap Build, no files or assets are transmitted externally.

Ultimately, the result of the Cordova/PhoneGap CLI and the various build environments is to make cross-platform development easier, and enable faster and more agile development (this in turn enables the enterprise to become far more mobile than ever before). Although there is still some native code available that is specific to each platform (including the wrapper around the app's HTML, CSS, and JavaScript and any additional plugins), the CLI makes managing these bits simple, and lets the developer focus on writing the truly cross-platform HTML, CSS, and JavaScript code.

The following diagram shows a simplified view of how this looks:

Easy cross-platform development

Cordova app architecture

The WWW or web code is inherently cross-platform (assuming web standards are followed) and should be the same on all platforms. Where necessary, different code paths can be built for specific devices, though this is usually only necessary when talking to certain third-party plugins that are specific to certain platforms.

This cross-platform web code is wrapped by native code. This code is specific to each platform the app supports (and so the app can only run on platforms supported by Cordova). This native code serves to bootstrap the app and instantiate a single full-screen system browser in which the web code is executed.

The native code initializes any native plugins as well; these can be core plugins provided by the Cordova team, third-party plugins developed by other members in the community, or custom plugins developed internally by the enterprise. This is a major benefit of using Cordova; if a particular feature isn't best handled or possible using web technologies, there can be a plugin developed by someone else that implements this feature. If there isn't such a plugin available, it's usually pretty easy to create such a plugin internally.

The native code also provides a bridge, or interface, between the native plugins and platform, and the web code. This bridge provides the mechanism by which the web code can access native device features by providing a simple and consistent API. This enables a web code to talk to specific plugins in order to perform native device functions.

The following diagram provides a bird's-eye view of how each layer talks to one another:

Cordova app architecture

Cordova app structure

A typical Cordova app has the following structure on the filesystem:

Cordova app structure

A typical Cordova project has a config.xml file in the root directory of the project that specifies the name, description, and other attributes for the project. There can be other files (such as a build script or a readme file, indicated by an asterisk in the previous diagram) that are also project-specific and internally developed by the enterprise to support the project. (If you want to see examples of these additional files, feel free to look at the code package for this book.)

Tip

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

All of the web code is put in the root www directory. There are other www directories in other various subdirectories (in the platforms directory); however, these are all duplicates and should be considered build artifacts (they are overwritten each time the project is built). As such, don't commit the platforms directory to your Version Control System (VCS).

The structure of the root www directory is specific to the project under development, and the various frameworks and libraries being used. The example in the preceding diagram is a portion of my typical directory structure within the www directory. Ultimately, there is neither a preferred nor mandated structure within this directory.

The hooks directory might not exist, and it should only be used if you need to perform custom actions when specific events occur in the project. For example, you might need to create a hook that notifies an external build system that the app's build was successful; such a hook will be created in this directory.

Note

Hooks are beyond the scope of this book as they are highly specific to each enterprise and app. However, there is a lot of information available online. The documentation at https://github.com/apache/cordova-lib/blob/master/cordova-lib/templates/hooks-README.md would be a good starting point.

The merges directory is another directory that might not exist and it should be avoided if at all possible. The original intent was to provide a way to override code in the www directory with platform-specific www code. If this code is correctly written according to the various web standards, then it is rarely necessary to use this functionality. If your app needs to behave differently on different devices, it is better to detect the device and branch appropriately.

The platforms directory includes every platform added to the project. As new platforms are added, native wrappers are created within this folder, and the www directory gets duplicated within these wrappers. Essentially, one should consider this directory a build artifact and it should never be checked into VCS.

The plugins directory includes every plugin added to the project. Similar to the platforms directory, it should be considered a build artifact and should never be checked into your VCS. The plugin management should instead be managed using the CLI or a shell script. If you want a good example, please check out the code package for this book.

None of this details how the www code should be structured or what architecture it should use. Cordova is not prescriptive in this regard—you can leverage your knowledge of the existing web frameworks (such as jQuery, Sencha Touch, and so on) and other libraries (such as Underscore, Backbone.js, and so on).

Summary

In this chapter, we introduced you to PhoneGap/Cordova and a little bit of its history. We covered the various environments you can use to develop a Cordova app. We also briefly touched upon the application's architecture. Finally, we covered the typical application structure used to create Cordova apps. Before moving on, you might want to visit Appendix A, More about PhoneGap/Cordova, which lists many sites that contain more information regarding PhoneGap and Cordova.

In the next chapter, we'll cover designing and implementing the business logic for your enterprise app built in PhoneGap/Cordova.

Left arrow icon Right arrow icon

Description

This book is intended for developers who wish to use PhoneGap to develop useful, rich, secure mobile applications for their enterprise environment. The book assumes you have working knowledge of PhoneGap, HTML5, CSS3, and JavaScript, and a reasonable understanding of networking and n-tier architectures.

What you will learn

  • Develop crossplatform mobile enterprise apps using PhoneGap
  • Understand the PhoneGap system and app architecture
  • Communicate between the mobile device and the backend using XHR and WebSockets for data transmission
  • Build a middle tier using Node.js to connect to the data store
  • Discover how PhoneGap allows you to whitelist trusted domains
  • Handle online/offline states by learning how to handle application and network status events

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Dec 26, 2014
Length: 192 pages
Edition : 1st
Language : English
ISBN-13 : 9781783554768
Vendor :
Apache
Category :
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Dec 26, 2014
Length: 192 pages
Edition : 1st
Language : English
ISBN-13 : 9781783554768
Vendor :
Apache
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 94.97
AngularJS Web application development Cookbook
€41.99
Phonegap for Enterprise
€24.99
PhoneGap and AngularJS for Cross-platform Development
€27.99
Total 94.97 Stars icon
Banner background image

Table of Contents

10 Chapters
1. PhoneGap and Enterprise Mobility Chevron down icon Chevron up icon
2. Building the Data Store and Business Logic Chevron down icon Chevron up icon
3. Securing PhoneGap Apps Chevron down icon Chevron up icon
4. Building the Middle-Tier Chevron down icon Chevron up icon
5. Communicating between Mobile and the Middle-Tier Chevron down icon Chevron up icon
6. Application Events and Storage Chevron down icon Chevron up icon
7. Push Notifications Chevron down icon Chevron up icon
8. Building the Presentation Tier Chevron down icon Chevron up icon
A. Useful Resources Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.5
(6 Ratings)
5 star 50%
4 star 50%
3 star 0%
2 star 0%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




Loiane Mar 31, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Phonegap for Enterprise is a great book! This is the book you should read if you want to take your phonegap knowledge to the next level. This is not a book for phonegap beginners, so if you are looking for a book to learn the basics about phonegap, I recommend the Phonegap Beginner's Guide (from Packt as well).If you already know the basics, this is the book for you. It covers apps that use a backend architecture (java, php, c# as backend deployed on the cloud), passing through REST services, security, best practices, storage (native sqlite) and also advanced topics such as push notifications (plugin). The appendix is full of external resources where you can learn even more about the technologies mentioned in the book.So if you already know the phonegap basics, I highly recommend reading this book.
Amazon Verified review Amazon
Charles A Carvey Mar 27, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Enterprises have a need to shorten the time to market for specific app needs. Kerri Shotts has outlined how PhoneGap can meet that need. The book deals with all three parts of the app ecosystem; the back end, the middle-ware, and the front end. Incorporating common patterns and security considerations makes this an excellent introduction for those charged with building PhoneGap apps in an enterprise environment. I highly recommend it to those developing hybrid apps in the enterprise.
Amazon Verified review Amazon
Captain Obvious Mar 31, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Throughout, PhoneGap for Enterprise addresses enterprise concerns in ways that are applicable to any hybrid development effort. While PhoneGap for Enterprise is focused on enterprise issues for PhoneGap development there is some nice coverage of PhoneGap\Cordova history in the first chapter. Not the best first book for those completely new to cross-platform development though - you need to be up and running to apply this material. Great addition to any mobile developers book shelf, highly recommend.
Amazon Verified review Amazon
Amazon Customer Apr 02, 2015
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
A good book, including an overview of technology choices and general and specific notes about how to make your application more secure... but also more likeable. It's definitely not a cookbook nor a how-to, as much as considerations and options which may apply to your application.The topics are somewhat scattered at times, ranging from very general considerations such as planning out your REST services first, to pieces often neglected such as security (what if my app is duplicated, what if someone spams my REST API), to an overview of some neat HTML5 tags. Despite covering this wide set of topics, each one is not overly detailed with pages-long code bits, but is quite rich in links to other resources -- having been given a point for consideration, resources are given to pick your own way.So again, not a cookbook and not really a tutorial/primer, as much as "don't just make an app, here are ideas to do it well". It's full of outside-the-box ideas, and full of options and links to other resources so you can take those ideas and run with them in your own direction. You'll probably find Phonegap for Enterprise a worthwhile read at any skill level with Cordova.
Amazon Verified review Amazon
Racykiwi Mar 31, 2015
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Kerri has written a highly readable tour through the main elements to consider when writing an enterprise level app. It covers much, but doesn't get too bogged down in detail. As such, it is possible (if you skim the code sections) to read the entire book in an evening.Much is made of security, and the great lengths that you have to go to to secure an enterprise grade application. This is the main focus of the first 5 chapters, which are quite generic in nature - they could equally apply to any web based application communicating with a server through an API, not specifically a PhoneGap one. Chapter 6 is the first time when you are required to set up a PhoneGap project to follow along the examples. This chapter is mainly about connectivity issues, network information and your app running in the background. Chapter 7 covers push notifications, using boxcar as the plugin provider, and chapter 8 puts it all together, although in a high-level way, briefly covering a raft of technologies such as Angular, Ember, Knockout, Backbone, React among others.One perhaps surprising omission is that there is no mention of testing or testing frameworks at all. For a book which touches lightly on so many topics I would have thought that this would have deserved a mention.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.