*** Developing Hybrid Applications for the iPhone
Preface
This book shows you how to create a new type of iPhone application: hybrid applications written in HTML, CSS, and JavaScript. Hybrid iPhone applications are standalone applications that run like regular applications on your iPhone, but don’t require the files to live on a server on the Internet.
Creating hybrid iPhone applications reduces creation time and the learning curve required to get your application into the hands of your customers, because you don’t have to learn Objective-C or have an intimate knowledge of the Cocoa frameworks.
Hybrid Application Development Tools
This book covers the two most commonly used open-source JavaScript software packages for writing applications for the iPhone and iPod touch devices: QuickConnectiPhone and PhoneGap. These packages enable you to build applications that access native device features directly from JavaScript, such as vibration, GPS location information, the accelerometer, and many other thingsmdall without writing a single line of Objective-C or Cocoa.
QuickConnectiPhone, downloaded from http://quickconnect.pbwiki.com, exposes the most native device behavior and provides a highly engineered, full-featured framework for development use. QuickConnectiPhone dramatically reduces your application’s time-to-market because part of the framework consists of all of the glue code you have to typically write in Objective-C, Cocoa, and JavaScript. Best of all, it does not require a remote server for hosting JavaScript, HTML, and CSS files.
The second package is PhoneGap, downloaded from http://phonegap.com. PhoneGap exposes fewer native behaviors and is a library rather than a full-fledged framework. As a library, PhoneGap enables you to engineer your application any way you want. It does, however, require a remote server for hosting files.
To reduce the learning curve and improve your understanding, good, solid examples are used throughout this book.
If you want to create installable iPhone applications, have the web skills required, and if you want to create dynamic, compelling solutions that people will use, this book shows you how using these two packages.
Table P1 compares what each package can do at the time of writing this book.
Table P1: Comparing the Features of QuickConnectiPhone and PhoneGap
Behavior/Data Available
QuickConnectiPhone
PhoneGap
GPS
Yes
Yes
Accelerometer
Yes
Yes
Vibrate
Yes
Yes
System sounds
Yes
Yes
Ad-hoc (Bonjour) networking
Yes
No
Sync cable networking
Yes
No
Browser-based database access
Yes
No
Shipped database access
Yes
No
Drag-and-drop library
Yes
No
AJAX wrapper
Yes
No
Record/Play audio files
Yes
No
Embedded Google maps
Yes
No
Charts and graphs library
Yes
No
How to Use This Book
Each chapter is organized into two parts. The first part shows you how to use the relevant feature of either QuickConnectiPhone or PhoneGap to accomplish a particular task, such as getting the current geolocation of the device. The second part of the chapter shows how the code behind the JavaScript call is written and how it works. You can decide how deep into the JavaScript and Objective-C you want to delve.
The book is organized as follows:
- Chapter 1, “Developing with Dashcode and Xcode,” teaches you how to use Dashcode and Xcode together with QuickConnectiPhone and PhoneGap to quickly create fun-to-use applications that run on the iPhone. This chapter includes basic Dashcode use and methods for moving your Dashcode application into Xcode for compiling and running on devices.
- Chapter 2, “JavaScript Modularity and iPhone Applications,” teaches you how to dramatically reduce your time to market by taking advantage of the modularity of the QuickConnectiPhone framework. How front controllers, application controllers, and JavaScript reflection are used in code is explained.
- Chapter 3, “Creating iPhone User Interfaces,” helps ensure that Apple App Store distribution approves your applications. It describes best practices for creating highly usable iPhone applications. The different types of applications usually created for iPhones are described as well as pitfalls to watch out for.
- Chapter 4, “GPS, Acceleration, and Other Native Functions with QuickConnectiPhone,” shows you how to get GPS, acceleration, and device description information, and it teaches you how to vibrate your phone and play and record audio files. You use the QuickConnectiPhone framework to access and use these device behaviors. These abilities give your applications a truly native, fun feel.
- Chapter 5, “GPS, Acceleration, and Other Native Functions with PhoneGap,” shows you how to get GPS, acceleration, and device description information as well as how to vibrate your phone and play and record audio files. You use the PhoneGap library to access and use these native device behaviors. These abilities give your applications a truly native, fun feel.
- Chapter 6, “Embedding Google Maps,” shows you how to put a Google map inside your application using QuickConnectiPhone. This is one of the most requested pieces of functionality that means you won’t have to send your users to the map application!
- Chapter 7, “Database Access,” shows you how to get information from and store data in SQLite databases included in your application created with the QuickConnectiPhone framework. Do you need to ship a predefined set of data in a database with your new applications? Read this chapter.
- Chapter 8, “Remote Data Access,” Do you need to access and use data from remote servers and/or services in your installed application? Chapter 8 shows you how to make this easy with a wrapper that lets you pull information from anywhere. Maybe you need to get data from an online blog and merge it with a Twitter feed. QuickConnectiPhone’s remote-data-access module makes it easy.
The following appendices are also included:
- Appendix A, “Introduction to JSON,” provides you with a brief introduction to JavaScript Object Notation (JSON). JSON is one of the most commonly used and easiest ways to transfer your data wherever it needs to go.
- Appendix B, “The QuickConnectiFamily Development Roadmap,” provides you with an overview of the growth of QuickConnectiPhone in the future. If you are planning on creating applications for iPhones and other platforms, such as Google’s Android phones, Nokia phones, Blackberries, and desktops such as Mac OS X, Linux, and Windows you should take a look at this appendix.
- Appendix C, “The PhoneGap Development Roadmap,” provides an overview of the growth of PhoneGap in the future. If you plan to create applications for iPhones and other platforms (such as Google’s Android phones, Nokia phones, and Blackberries) and desktops (such as Mac OS X, Linux, and Windows), you should take a look at this appendix.
Online Resources
QuickConnectiPhone and PhoneGap are undergoing rapid development. To keep up with the new functions and capabilities and to learn more, use the following links.
QuickConnectiPhone:
- Download examples and the framework from https://sourceforge.net/projects/quickconnect/.
- Review the development blog at http://tetontech.wordpress.com.
- Read the Wiki at http://quickconnect.pbwiki.com/FrontPage.
- Find the Google group at http://groups.google.com/group/quickconnectiPhone/,
- Twitter at http://twitter.com/quickconnect.
PhoneGap:
- Download examples and the framework from https://sourceforge.net/projects/phonegapinstall/.
- Visit the web site at http://www.phonegap.com/.
- Read the Wiki at http://phonegap.pbwiki.com/.
- Find the Google group at http://groups.google.com/group/phonegap.
- Twitter at http://twitter.com/phonegap.
Prerequisites
You need a basic understanding of HTML, CSS, and Javascript to effectively use this book. If you have created web pages using these tools, you are well on your way to creating iPhone applications. If you need help with Objecive-C in both QuickConnectiPhone and PhoneGap, it is provided. This book is not intended to be an introductory book on Objective-C or on how to use it to develop iPhone applications.
You need to download and install Apple’s Xcode tools from the iPhone developer web site at http://developer.apple.com/iphone. This requires Mac OS X 10.5 or greater and an Intel-based Mac.
Although it isn’t required, you should also have either an iPhone or an iPod touch, so you can test and run the applications on those devices.
Contacting the Author
To contact the author by email, use quickconnectfamily@gmail.com. For other types of contact, use Twitter, the Wiki, and Google Group links provided earlier.
© Copyright Pearson Education. All rights reserved.