About This eBook
ePUB is an open, industry-standard format for eBooks. However, support of ePUB and its many features varies across reading devices and applications. Use your device or app settings to customize the presentation to your liking. Settings that you can customize often include font, font size, single or double column, landscape or portrait mode, and figures that you can click or tap to enlarge. For additional information about the settings and features on your reading device or app, visit the device manufacturers Web site.
Many titles include programming code or configuration examples. To optimize the presentation of these elements, view the eBook in single-column, landscape mode and adjust the font size to the smallest setting. In addition to presenting code and configurations in the reflowable text format, we have included images of the code that mimic the presentation found in the print book; therefore, where the reflowable format may compromise the presentation of the code listing, you will see a Click here to view code image link. Click the link to view the print-fidelity code image. To return to the previous page viewed, click the Back button on your device or app.
Apache Cordova 3 Programming
John M. Wargo
Upper Saddle River, NJ Boston Indianapolis San Francisco
New York Toronto Montreal London Munich Paris Madrid
Capetown Sydney Tokyo Singapore Mexico City
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals.
The author and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein.
For information about buying this title in bulk quantities, or for special sales opportunities (which may include electronic versions; custom cover designs; and content particular to your business, training goals, marketing focus, or branding interests), please contact our corporate sales department at or (800) 382-3419.
For government sales inquiries, please contact .
For questions about sales outside the U.S., please contact
Copyright 2014 Pearson Education, Inc.
All rights reserved. This publication is protected by copyright, and permission must be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. To obtain permission to use material from this work, please submit a written request to Pearson Education, Inc., Permissions Department, One Lake Street, Upper Saddle River, New Jersey 07458, or you may fax your request to (201) 236-3290.
Apache Cordova website, PhoneGap, and PhoneGap Build screenshots Adobe Systems Incorporated. All rights reserved. Adobe, PhoneGap, and PhoneGap Build is/are either [a] registered trademark[s] or trademark[s] of Adobe Systems Incorporated in the United States and/or other countries.
ISBN-13: 978-0-321-95736-8
ISBN-10: 0-321-95736-9
First released, December 2013
To my wife, Anna.
This work exists because of your outstanding support.
To my children,
who were relatively patient as I worked on yet another book.
Foreword
It has been roughly twenty-five years now since the mobile technology era began. Can it be just a coincidence that it is almost exactly the same amount of time that I have known John Wargo, the author of this book? In 1988, the mobile technology landscape consisted of mobile phones the size of a carry-on suitcase and personal organizers that looked like glorified financial calculators. Wireless networks and widespread access to resources like the Internet were distant dreams. Unless you were a science fiction writer, it would have been hard to imagine the connected world that we take for granted today. If you knew John Wargo as I do, though, it would not have been very far-fetched at all to predict that he would turn out to be the author of four books.
Looking ahead another twenty-five years, I imagine its safe to say that our ability to accurately predict the advance of technology will continue to fall short. Powerful development tools like Cordova and the combined creativity of millions of application developers around the world virtually guarantee that we wont be able to guess what indispensable capabilities will appear on our mobile devices tomorrow or the next day. Will tomorrows devices interface directly to our human nervous systems? Will they assemble themselves from organic compounds and heal themselves if they become damaged? Who knows.
Whatever the future of mobile technology holds for us, as long as there is a means to program or control it in some way, I hope that John will put together a collection of words to point others in the right direction.
David M. Via
AT&T
Preface
This is a book about programming cross-platform mobile applications using Apache Cordova 3 (with some coverage of PhoneGap 3 as well). In Apache Cordova 3, the Cordova development team made some dramatic changes in the framework, and this book is what you need to understand what Cordova 3 is all about. The book can be considered as a sequel to my PhoneGap Essentials, updated for Cordova 3.
This is a book about Cordova 3. This book is targeted at mobile developers who want to learn about Cordova 3. If youre brand new to Cordova, then this book is just what you need to get started. If youre experienced with an older version of Cordova, this book will show you in detail how to use all of the new stuff thats in Cordova 3. You will, however, need to have at least some experience with mobile development to benefit from this book. The target audience could be existing web developers who want to get into mobile development, but much of the needed native mobile development background just isnt in here.
What youll find in the book:
Lots of detailed information about Apache Cordova: what it does and how it works
Lots of examples and code
What you wont find in this book:
Mobile web development and mobile development topics; this book is about Apache Cordova, not mobile development
Expressions or phrases in languages other than English (I hate it when authors include phrases in Latin or French)
Obscure references to pop-culture topics (although there is an overt reference to Douglas Adamss Hitchhikers Guide to the Galaxy and one obscure reference to Monty Python)
Pictures of my children or my pets
This book is not a book for experienced Cordova 3 developersif you consider yourself an experienced Cordova 3 developer, then you probably should not buy this book.
Herein I tried to provide complete coverage of Cordova 3; covering enough detail that readers will leave with a complete understanding of what Cordova is, what it does, how it works, and how to use it for their mobile application projects. Theres a whole lot more to Cordova; many advance topics and more detailed coverage of the Cordova APIs can be found in the Cordova documentation and maybe in some future book Ill write.