iPhone JavaScript Cookbook offers a set of practical and clear recipes with a step
-by-step approach for building your own iPhone applications by only applying ...
iPhone JavaScript Cookbook
Arturo Fernandez Montoro
Chapter No.8 "This is a Phone"
In this package, you will find: A Biography of the author of the book A preview chapter from the book, Chapter NO.8 "This is a Phone" A synopsis of the book’s content Information on where to buy this book
About the Author Arturo Fernandez Montoro is a web software engineer, developer, author, and technical writer specializing in Free and Open Source Software. His professional experience includes technologies, such as Django, Rails, J2EE, PHP, XHTML, CSS, and JavaScript, and working as a software developer and architect, project manager, sysadmin, and consultant for different companies in Europe. Since 2002, he often writes for different Linux and Open Source printed and online magazines, such as Todo Linux, Linux+, Linux Magazine, Free Software Magazine, and Rails Magazine.
For More Information: www.PacktPub.com/iphone-javascript-cookbook/book
Currently, Arturo works as a Python/Django developer, contributing to one of the most important and visited websites in Spain. He can be reached at
[email protected]. Many thanks to my friends and colleagues Lui Palacios and Thomas Schreiber for contributing to this book with their advice and revisions. My wife Alicia is a living proof of the power of love. Thank you for starting a family together. This book would have never been possible without the help and work of the team at Packt Publishing. My sincere acknowledgements to Steven, Zainab, and Alina. Special thanks to all people who contribute to Free and Open Source with their knowledge, effort, time, patience, and enthusiasm. We’re changing the world. Thanks to my parents Jose and Aurora for teaching me to be the person I am today. My brother Ernesto is someone who never gives up. Thank you for making my life enjoyable. In memoriam of my grandmother Aurora, who passed away during the writing of this book.
For More Information: www.PacktPub.com/iphone-javascript-cookbook/book
iPhone JavaScript Cookbook Undoubtedly, iPhone is one of the most exciting mobile devices in the world. Its iOS is used in other Apple devices, such as iPad and iPod Touch. With this book, you'll learn how to build and develop applications for these devices without applying Apple's burdensome and, at times, restrictive technologies. Just use your experience and knowledge combined with web frontend technologies, such as JavaScript, to build quality web applications. Nobody will ever come to know that you haven't used Objective-C and Cocoa. iPhone JavaScript Cookbook offers a set of practical and clear recipes with a step-by-step approach for building your own iPhone applications by only applying web technologies such as JavaScript and AJAX. Web developers won't need to learn a new programming language for building iOS applications with a native look and feel.
What This Book Covers Chapter 1, Frameworks Make Life Easier, is the "getting started" chapter of this book. It covers how to install and set up different frameworks, which will be used for the recipes of the book. Chapter 2, Building Interfaces, introduces you to the world of iPhone applications. You'll learn how to build essential and advanced interfaces, such as buttons, lists, forms, and date pickers. Chapter 3, Events and Actions, discovers how to deal with events and actions. Both allow us a better control of the interaction between the user and the device. Chapter 4, A Picture Speaks a Thousand Words, takes advantage of the great screens of iPhone and iPad teaching you how to display a grid of images, how to apply different effects, and how to work with the built-in camera of the device. Chapter 5, Mastering Sound and Music, explores the audio and video capabilities of iPhone. You'll learn how to play and record audio and how to create iPod playlists.
For More Information: www.PacktPub.com/iphone-javascript-cookbook/book
Chapter 6, Exchanging Data: AJAX, covers how to use this technology for exchanging data between the server and the client. Readers are walked through the process of sending HTTP requests and processing JSON responses. Chapter 7, Working with Data: Storage and SQL, provides coverage of the process for storing and retrieving data using the SQL language. Also, you'll learn how to deal with different kinds of storage available in iPhone. Chapter 8, This is a Phone, enlightens that we cannot forget that iPhone is a smartphone. This is the reason to get focused on learning how to create, select and display contacts, and how to call a number and send an SMS. Chapter 9, Location, Location, Location, introduces to readers to geolocation, showing how to detect the current orientation and position, and how to use the API provided by Google Maps for displaying a map at a specific location. Chapter 10, Web 2.0 Integration, helps readers learn how to integrate their iPhone applications with third-party popular services such as Facebook, YouTube, Twitter, and Flickr.
For More Information: www.PacktPub.com/iphone-javascript-cookbook/book
8
This is a Phone In this chapter, we will cover: f
Calling a number
f
Sending an SMS to a number
f
Selecting contacts
f
Creating a new contact
f
Searching and displaying contacts
Introduction Although iPhone is a smartphone, we shouldn't forget its main functionality of making phone calls and sending text messages in addition to its other rich features. This chapter will teach you how to use the contacts stored in the internal address book of the device. At the time of publication, working with contacts requires us to develop native applications. But we can use JavaScript with the PhoneGap framework for building these kinds of applications for the iPhone. This is the main reason for applying this framework for the recipes included in the current chapter. This chapter focuses on issues related to calls, SMS, and contacts. We'll learn how to handle contacts and how to send an SMS or place a phone call simply by interacting with the user interface.
For More Information: www.PacktPub.com/iphone-javascript-cookbook/book
This is a Phone
Calling a number In this recipe, you'll learn how to call a number when a user clicks on a button in the user interface. Specifically, we're going to build a simple list containing our contacts where each represents a person and their phone number. After clicking on one of these elements the dial screen will be opened and the user will only need to click on the green button for calling the specified number. We only need to build a simple XHTML file for this recipe. It can be found at code/ch08/call.html in the code bundle provided on the Packtpub site.
Code files can be downloaded at the Packt website.
Getting ready This recipe requires the use of the iWebKit framework.
How to do it... Open your favorite text editor or IDE and create a new file called call.html. 1. Add the standard XHTML headers and the required lines for invoking the JavaScript and CSS files provided by iWebKit: