ebook img

Beginning iOS 4 Application Development PDF

673 Pages·2·34.143 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Beginning iOS 4 Application Development

www.it-ebooks.info www.it-ebooks.info Beginning iOS 4 ApplicAtiOn DevelOpment intrODuctiOn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xvii ⊲ pArt i getting StArteD chApter 1 Getting Started with iOS 4 Programming . . . . . . . . . . . . . . . . . . . . . . . . . . 3 chApter 2 Write Your First Hello World! Application . . . . . . . . . . . . . . . . . . . . . . . . .23 chApter 3 Views, Outlets, and Actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 chApter 4 View Controllers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 chApter 5 Multi-Platform Support for the iPhone and iPad . . . . . . . . . . . . . . . . . . 133 chApter 6 Keyboard Inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 chApter 7 Screen Rotations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181 ⊲ pArt ii DiSplAying AnD perSiSting DAtA chApter 8 Using the Table View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197 chApter 9 Application Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241 chApter 10 File Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261 chApter 11 Database Storage Using SQLite3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279 ⊲ pArt iii ADvAnceD iOS 4 prOgrAmming techniqueS chApter 12 Simple Animations and Video Playback . . . . . . . . . . . . . . . . . . . . . . . . .297 chApter 13 Accessing Built-In Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319 chApter 14 Recognizing Gestures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343 chApter 15 Accessing the Accelerometer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 385 ⊲ pArt iv netwOrk prOgrAmming techniqueS chApter 16 Web Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .403 chApter 17 Bluetooth Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 421 chApter 18 Bonjour Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 441 chApter 19 Apple Push Notification Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 455 Continues www.it-ebooks.info chApter 20 Displaying Maps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 477 chApter 21 Background Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .519 ⊲ pArt v AppenDiceS AppenDix A Testing on an Actual Device . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 541 AppenDix B Getting Around in Xcode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 565 AppenDix c Getting Around in Interface Builder . . . . . . . . . . . . . . . . . . . . . . . . . . . . .577 AppenDix D Crash Course in Objective-C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 591 AppenDix e Answers to Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Wrox .com inDex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 619 www.it-ebooks.info Beginning iOS 4 Application Development Wei-Meng Lee www.it-ebooks.info Beginning iOS 4 Application Development Published by Wiley Publishing, Inc. 10475 Crosspoint Boulevard Indianapolis, IN 46256 www.wiley.com Copyright © 2010 by Wiley Publishing, Inc., Indianapolis, Indiana Published simultaneously in Canada ISBN: 978-0-470-91802-9 ISBN: 978-0-470-94983-2 (ebk) ISBN: 978-1-118-00480-7 (ebk) ISBN: 978-1-118-00481-4 (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 specifically disclaim all warranties, including without limitation warranties of fitness for a particular purpose. No warranty may be created or extended by sales or pro- motional 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 pub- lisher 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 also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books. Library of Congress Control Number: 2010932418 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 affiliates, in the United States and other coun- tries, and may not be used without written permission. All other trademarks are the property of their respective owners. Wiley Publishing, Inc. is not associated with any product or vendor mentioned in this book. www.it-ebooks.info To my family: Thanks for the understanding and support while I worked on getting this book ready! I love you all! www.it-ebooks.info creDitS AcquiSitiOnS eDitOr vice preSiDent AnD Scott Meyers executive grOup puBliSher Richard Swadley SeniOr prOject eDitOr Ami Frank Sullivan vice preSiDent AnD executive puBliSher Barry Pruett technicAl eDitOr Trenton Shumay ASSOciAte puBliSher Jim Minatel prODuctiOn eDitOr Rebecca Anderson prOject cOOrDinAtOr, cOver Lynsey Stanford cOpy eDitOr Luann Rouff cOmpOSitOr James D . Kramer, eDitOriAl DirectOr Happenstance Type-O-Rama Robyn B . Siesky prOOfreADer eDitOriAl mAnAger Nancy Carrasco Mary Beth Wakefield inDexer ASSOciAte DirectOr Of mArketing Johnna VanHoose Dinse David Mayhew cOver DeSigner prODuctiOn mAnAger Michael E . Trent Tim Tate cOver imAge © istockphoto .com/-M-I-S-H-A- www.it-ebooks.info ABOut the AuthOr wei-meng lee is a technologist and founder of Developer Learning Solutions (www.learn2develop.net), a technology company specializing in hands-on training for the latest Microsoft and Mac OS X tech- nologies. He is also an established author with Wrox and O’Reilly. Wei-Meng first started the iPhone programming course in Singapore, and it has since received much positive feedback. His hands-on approach to iPhone/iPad programming makes understanding the subject much easier than reading books, tutorials, and documentation from Apple. Contact Wei-Meng at [email protected]. ABOut the technicAl eDitOr trent ShumAy is the founder and Chief Architect at Finger Food Studios Inc. in the Vancouver, BC area. After graduating from the UBC Computer Science program, Trent spent thirteen years in the gaming and interactive entertainment space, where handheld gaming devices ignited his passion for mobile development. Today, Finger Food Studios focuses on developing media-rich, interactive mobile and Web applications. You can reach Trent directly at [email protected]. www.it-ebooks.info AcknOwleDgmentS After much SpeculAtiOn and rumor, Apple has finally released the iPhone 4 amid fanfare and excitement. With the new iPhone 4 comes a new OS — iOS 4, which incorporates many enhance- ments, most notably the ability to support background applications. I was very fortunate to be able to work with the new OS while it was in its beta phase and even more excited to learn that I would be working on an iPhone 4 book! Writing a book is always exciting, but along with it come long hours of hard work, straining to get things done accurately and correctly. For this, I would like to take this opportunity to thank a number of people who made this book possible. First, I want to thank my acquisitions editor Scott Meyers, who had faith in me when he signed me up for this book. Thanks for standing by me and always being there to help. I hope I have not disap- pointed you. Thank you, Scott! Next, a huge thanks to Ami Sullivan, my editor, who is always a pleasure to work with. After work- ing together on three books, we have built up a rapport and totally understand how each other works. With every new book that I work on with Ami, I learn new things. Thanks for the guidance, Ami! I should not forget the heroes behind the scene: copy editor Luann Rouff and technical editor Trenton Shumay. They have been eagle-eye editing the book, making sure that every sentence makes sense — both grammatically as well as technically. Thanks, Luann and Trent! Last, but not least, I want to thank my parents, and my wife, Sze Wa, for all the support they have given me. They have selflessly adjusted their schedules to accommodate my busy schedule when I was working on this book. My wife, as always, has stayed up with me on numerous nights as I was furiously working to meet the deadlines, and for this I would like to say to her and my parents: “I love you all!” Finally, to our lovely dog, Ookii, thanks for staying by our side. Now that the book is done, we can look forward to an earlier night. www.it-ebooks.info

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.