www.it-ebooks.info ffirs.indd ivffirs.indd iv 12/21/11 2:29:58 PM12/21/11 2:29:58 PM www.it-ebooks.info BEGINNING IOS APPLICATION DEVELOPMENT WITH HTML AND JAVASCRIPT® INTRODUCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii PART I GETTING STARTED CHAPTER 1 Introducing iOS Development Using Web Technologies . . . . . . . . . . . . . 3 CHAPTER 2 Working with Core Technologies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 CHAPTER 3 The Document Object Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 CHAPTER 4 Writing Your First Hello World Application . . . . . . . . . . . . . . . . . . . . . . . . 65 CHAPTER 5 Enabling and Optimizing Web Sites for the iPhone and iPad . . . . . . . . 79 PART II APPLICATION DESIGN CHAPTER 6 Designing the iPhone UI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 CHAPTER 7 Designing for iPad . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 CHAPTER 8 Styling with CSS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 PART III APPLICATION DEVELOPMENT CHAPTER 9 Programming the Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 CHAPTER 10 Handling Touch Interactions and Events . . . . . . . . . . . . . . . . . . . . . . . . . 189 CHAPTER 11 Special E ects and Animation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207 CHAPTER 12 Integrating with iOS Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223 CHAPTER 13 Packaging Apps as Bookmarks: Bookmarklets and Data URLs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235 PART IV ADVANCED PROGRAMMING TECHNIQUES CHAPTER 14 Programming the Canvas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251 CHAPTER 15 O ine Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269 CHAPTER 16 Building with Web App Frameworks . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287 CHAPTER 17 Bandwidth and Performance Optimizations . . . . . . . . . . . . . . . . . . . . . . 303 CHAPTER 18 Debug and Deploy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317 ffirs.indd iffirs.indd i 12/21/11 2:29:56 PM12/21/11 2:29:56 PM www.it-ebooks.info PART V NEXT STEPS: DEVELOPING NATIVE IOS APPLICATIONS WITH HTML AND JAVASCRIPT CHAPTER 19 Preparing for Native iOS Development . . . . . . . . . . . . . . . . . . . . . . . . . . 333 CHAPTER 20 PhoneGap: Native Apps from Your HTML, CSS, and JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345 CHAPTER 21 Submitting Your App to the App Store . . . . . . . . . . . . . . . . . . . . . . . . . . . 363 APPENDIX Exercise Answers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375 INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .381 ffirs.indd iiffirs.indd ii 12/21/11 2:29:58 PM12/21/11 2:29:58 PM www.it-ebooks.info BEGINNING iOS Application Development with HTML and JavaScript ® ffirs.indd iiiffirs.indd iii 12/21/11 2:29:58 PM12/21/11 2:29:58 PM www.it-ebooks.info ffirs.indd ivffirs.indd iv 12/21/11 2:29:58 PM12/21/11 2:29:58 PM www.it-ebooks.info BEGINNING iOS Application Development with HTML and JavaScript ® Richard Wagner John Wiley & Sons, Inc. ffirs.indd vffirs.indd v 12/21/11 2:29:58 PM12/21/11 2:29:58 PM www.it-ebooks.info Beginning iOS Application Development with HTML and JavaScript® Published by John Wiley & Sons, Inc. 10475 Crosspoint Boulevard Indianapolis, IN 46256 w w w.wile y .com Copyright © 2012 by John Wiley & Sons, Inc., Indianapolis, Indiana Published simultaneously in Canada ISBN: 978-1-118-15900-2 ISBN: 978-1-118-22607-0 (ebk) ISBN: 978-1-118-23751-9 (ebk) ISBN: 978-1-118-26405-8 (ebk) Manufactured in the United States of America 10 9 8 7 6 5 4 3 2 1 No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions. Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with respect to the accuracy or completeness of the contents of this work and specifi cally disclaim all warranties, including without limitation warranties of fi tness for a particular purpose. No warranty may be created or extended by sales or promotional materials. The advice and strategies contained herein may not be suitable for every situation. This work is sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional services. If professional assistance is required, the services of a competent professional person should be sought. Neither the publisher nor the author shall be liable for damages arising herefrom. The fact that an organization or Web site is referred to in this work as a citation and/or a potential source of further information does not mean that the author or the publisher endorses the information the organization or Web site may provide or recommendations it may make. Further, readers should be aware that Internet Web sites listed in this work may have changed or disappeared between when this work was written and when it is read. For general information on our other products and services please contact our Customer Care Department within the United States at (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002. Wiley publishes in a variety of print and electronic formats and by print-on-demand. Some material included with standard print versions of this book may not be included in e-books or in print-on-demand. If this book refers to media such as a CD or DVD that is not included in the version you purchased, you may download this material at http ://booksupport.wiley.com. For more information about Wiley products, visit w w w.wiley.co m. Library of Congress Control Number: 2011945668 Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Wrox Programmer to Programmer, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affi liates, in the United States and other coun- tries, and may not be used without written permission. JavaScript is a registered trademark of Oracle America, Inc. All other trademarks are the property of their respective owners. John Wiley & Sons, Inc., is not associated with any product or vendor mentioned in this book. ffirs.indd viffirs.indd vi 12/21/11 2:30:03 PM12/21/11 2:30:03 PM www.it-ebooks.info To KimmyWags and the J-Team ffirs.indd viiffirs.indd vii 12/21/11 2:30:03 PM12/21/11 2:30:03 PM www.it-ebooks.info ffirs.indd viiiffirs.indd viii 12/21/11 2:30:04 PM12/21/11 2:30:04 PM www.it-ebooks.info [...]... apps for iOS using familiar web technologies DISCOVERING THE SAFARI ON IOS PLATFORM An iOS web application runs inside the built-in Safari browser that is based on web standards, including the following: ➤ HTML/ XHTML (HTML 4.01 and XHTML 1.9, XHTML mobile profi le document types) ➤ CSS (CSS 2.1 and partial CSS3) www.it-ebooks.info c01.indd 3 12/22/11 8:48:52 AM 4 ❘ CHAPTER 1 INTRODUCING IOS DEVELOPMENT. .. an iPhone and iPad web application interface 10 Handling Touch Interactions and Events The heart of an iOS device is its touch screen interface This chapter explores how to handle touch interactions and capture JavaScript events 11 Special Effects and Animation The Safari canvas provides an ideal environment for advanced graphic techniques, including gradients and masks 12 Integrating with iOS Services... CONTENTS PART V: NEXT STEPS: DEVELOPING NATIVE IOS APPLICATIONS WITH HTML AND JAVASCRIPT CHAPTER 19: PREPARING FOR NATIVE IOS DEVELOPMENT 333 Downloading Xcode Joining the iOS Developer Program Getting an iOS Developer Certificate Retrieving the Developer Certificate Adding a Device for Testing Creating an App ID Creating a Provisioning Profile Installing the Development Provisioning Profile 333 334 335 337... web-based applications for iOS Specifically, you will discover how to create a mobile application from the ground up, utilize existing open source frameworks to speed up your development times, emulate the look and feel of built-in Apple applications, capture finger touch interactions, and optimize applications for Wi-Fi and wireless networks WHO THIS BOOK IS FOR This book is aimed primarily for beginning and. .. readers to the web application platform for iOS It guides readers through the process of building new applications from scratch and migrating existing web applications to this new mobile platform As it does so, it helps readers design a user interface that is optimized for iOS touch-screen displays and integrate their applications with iPhone services, including Phone, Mail, Google Maps, and GPS HOW THIS... ine Applications Covers how you can use HTML 5 offl ine cache to create local web apps that don’t need a live server connection 16 Building with Web App Frameworks Highlights the major open source iPhone web app frameworks and shows you how to be productive quickly with each of them 17 Bandwidth and Performance Optimizations Deals with the all-important issue of performance of web-based applications and. .. work with an HTML page as a tree in order to navigate and control various parts in your app 4 Writing Your First Hello World Application Guides you through the steps needed to create your fi rst iOS app 5 Enabling and Optimizing Web Sites for iPhone and iPad Covers how to make an existing website compatible with mobile versions of Safari and then how to optimize the site for use as a full-fledged web application. .. about how the forum software works, as well as many common questions specific to P2P and Wrox books To read the FAQs, click the FAQ link on any P2P page xxvii www.it-ebooks.info flast.indd xxvii 12/21/11 8:06:48 AM www.it-ebooks.info flast.indd xxviii 12/21/11 8:06:51 AM BEGINNING iOS Application Development with HTML and JavaScript www.it-ebooks.info flast.indd xxix 12/21/11 8:06:51 AM www.it-ebooks.info... WEB TECHNOLOGIES ➤ JavaScript (ECMAScript 3 (ECMA 262), JavaScript 1.4) ➤ AJAX (for example, XMLHTTPRequest) ➤ SVG (Scalable Vector Graphics) 1.1 ➤ HTML5 media tags ➤ Ancillary technologies (video and audio media, PDF, and so on) Safari on iOS (which I refer to throughout the book interchangeably as Safari or Safari on iOS) becomes the platform upon which you develop applications and becomes the shell... 277 278 Going SQL with the JavaScript Database Open a Database Querying a Table 283 283 283 xix www.it-ebooks.info ftoc.indd xix 12/21/11 2:35:56 PM CONTENTS CHAPTER 16: BUILDING WITH WEB APP FRAMEWORKS Using jQuery Mobile Using iWebKit 287 288 293 CHAPTER 17: BANDWIDTH AND PERFORMANCE OPTIMIZATIONS Optimization Strategies Best Practices to Minimize Bandwidth General Images CSS and JavaScript 303 303 . IOS APPLICATIONS WITH HTML AND JAVASCRIPT CHAPTER 19 Preparing for Native iOS Development . . . . . . . . . . . . . . . . . . . . . . . . . . 333 CHAPTER 20 PhoneGap: Native Apps from Your HTML, . ivffirs.indd iv 12/21/11 2:29:58 PM12/21/11 2:29:58 PM www.it-ebooks.info BEGINNING IOS APPLICATION DEVELOPMENT WITH HTML AND JAVASCRIPT INTRODUCTION . . . . . . . . . . . . . . . . . . . . . iiffirs.indd ii 12/21/11 2:29:58 PM12/21/11 2:29:58 PM www.it-ebooks.info BEGINNING iOS Application Development with HTML and JavaScript ® ffirs.indd iiiffirs.indd iii 12/21/11 2:29:58 PM12/21/11