PhoneGap Tutorial: A Cross-Platform Zombie App
PhoneGap is a mobile development framework that allows developers to build applications for a variety of mobile platforms, using familiar web technologies such as HTML, CSS, and JavaScript. By Dani Arnaout.
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Contents
PhoneGap Tutorial: A Cross-Platform Zombie App
35 mins
PhoneGap is a mobile development framework that allows developers to build applications for a variety of mobile platforms, using familiar web technologies such as HTML, CSS, and JavaScript.
The concept is that you can develop one application using the PhoneGap architecture, and then deploy to multiple mobile platforms — without the need to re-write any code!
In this tutorial, you’ll learn the basics of using PhoneGap to make a simple to-do app, with a twist – it’s an app to help you survive the Zombie Apocalypse!
In the process, you’ll learn a ton about PhoneGap – such as installing PhoneGap, writing Javascript code, using local storage, and much more.
This tutorial assumes you have some basic familiarity with HTML, CSS, and Javascript. If you are new to these technologies you can still follow along with the tutorial, but you’ll be missing some background knowledge, so I recommend you read a book on those when you get a chance.
So if you think you have the brains, keep reading to get started – the zombies are waiting!
Getting Started
As with any new project, it’s always a good idea to plan ahead for what you’ll be building.
Here’s a sketch of what the app you’re developing will look like:
Basically this is an app to help you keep track of all the things you need to do in order to survive the Zombie Apocalypse.
The app’s logo sits at the top of the screen. Two buttons sit below the logo; one for adding a new task, and another for removing completed ones. When the user adds an item to their to-do list, a new table row will appear with four individual elements.
First, you have a checkbox which indicates a task’s status. Next is the content of the to-do item. Then, finally, there are two more buttons: one that will displays the text of the to-do item in a popup dialog, and another that will delete the to-do item.
The app will store the to-do list using the Local Storage API.
And, thanks to the graphic design talents of Vicki Wenderlich, this is how the final app will look:
Aww yeah. You’d never forget your zombie repellent spray if you had an app like that! :]
That’s it for the look and feel — time to take a look at how the app should behave.
- Adding a task: When tapping the Add To-Do button, the user will be prompted to enter some text for their to-do list item.
- Marking tasks as completed: The user will be able to mark tasks as completed by tapping the check box to the left of the task.
- Removing completed tasks: Tapping the Remove Completed Tasks button will remove all completed tasks.
- Viewing a task: When tapping the View button, the full text of the task will be displayed.
- Deleting a task Tapping the Delete button will remove the corresponding task.
Altogether, it’s a relatively simple app. The purpose behind this PhoneGap tutorial is to demonstrate the development of a fully functional app without using any native code, and make it available on a variety of mobile platforms with nothing more than a single click!
Sound good? All right — time to get PhoneGap installed!
Installing PhoneGap
Note: If you already have PhoneGap and want to get started immediately, skip this section and download the starter project. If you choose to skip ahead, I encourage you to have a read through the official PhoneGap getting started guide and command line usage documentation, once you’ve completed the PhoneGap tutorial.
Note: If you already have PhoneGap and want to get started immediately, skip this section and download the starter project. If you choose to skip ahead, I encourage you to have a read through the official PhoneGap getting started guide and command line usage documentation, once you’ve completed the PhoneGap tutorial.
Head over to the PhoneGap website, and choose Download PhoneGap from the home page.
Click the big blue Download button on the next page to initiate the download, as shown in the screenshot below:
Unarchive the folder, and you might want to save it somewhere safe on your hard drive. And that’s all there is to installing PhoneGap!
It’s now time to create your project. Open up the Terminal app. It’s usually found in the Applications folder, within the Utilities folder. You’ll be presented with the Terminal interface, as below:
Type the following command in Terminal and hit enter (but replace the path with wherever your copy of PhoneGap is):
cd ~/Downloads/phoneGap-2.3.0/lib/ios/bin
Note: At the time of this writing, the most recent version of PhoneGap was 2.3.0. If the version you’ve downloaded is newer, then please replace the version number in the command above with the version you have.
Note: At the time of this writing, the most recent version of PhoneGap was 2.3.0. If the version you’ve downloaded is newer, then please replace the version number in the command above with the version you have.
To generate a new project, you need to use the command line script create, and pass in the project location, the bundle identifier and finally the project name as arguments to the call.
Type the following command into Terminal and hit Return to generate the project:
./create ~/Desktop/Zombie com.raywenderlich.zombie ZombieApocalypseToDoList
You’ll now find a Zombie folder on your desktop. Open it up, dive into the www folder and take a look at the files inside, as shown below:
The three key files and folders here are index.html, which is where you’ll be writing the app’s code; index.css, found in the css folder, which is used to style the look and feel of the app; and finally the img folder, which is where all the images for the app will be stored.
Go back to the top level folder and open up the ZombieApocalypseToDoList.xcodeproj file in Xcode.
In Xcode’s project navigator, open index.html. Then build and run your app. “Already?” you ask. Yes! Already! :]
You should see the following:
If your display matches the screenshot above, then everything is set up properly for your PhoneGap development environment.
Installation was a breeze – even the undead could have handled that one! :]
You’ll find that the coding of your PhoneGap app in the next section is almost as easy!