1. Trang chủ
  2. » Công Nghệ Thông Tin

beginning ios 4 application development

673 353 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 673
Dung lượng 34,14 MB

Nội dung

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 I  I 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 II  I 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 I  V 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 ACQUISITIONS EDITOR Scott Meyers SENIOR PROJECT EDITOR Ami Frank Sullivan TECHNICAL EDITOR Trenton Shumay PRODUCTION EDITOR Rebecca Anderson COPY EDITOR Luann Rou EDITORIAL DIRECTOR Robyn B. Siesky EDITORIAL MANAGER Mary Beth Wakefield ASSOCIATE DIRECTOR OF MARKETING David Mayhew PRODUCTION MANAGER Tim Tate VICE PRESIDENT AND EXECUTIVE GROUP PUBLISHER Richard Swadley VICE PRESIDENT AND EXECUTIVE PUBLISHER Barry Pruett ASSOCIATE PUBLISHER Jim Minatel PROJECT COORDINATOR, COVER Lynsey Stanford COMPOSITOR James D. Kramer, Happenstance Type-O-Rama PROOFREADER Nancy Carrasco INDEXER Johnna VanHoose Dinse COVER DESIGNER Michael E. Trent COVER IMAGE © istockphoto.com/-M-I-S-H-A- CREDITS 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 weimenglee@learn2develop.net . 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 trent@fingerfoodstudios.com . 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 [...]... Summary 45 7 46 1 46 2 46 5 46 7 46 7 47 1 47 5 47 7 47 7 48 3 48 9 49 3 49 8 5 04 509 513 515 Chapter 21: Background Applications Understanding Background Execution on the iPhone Examining the Different Application States Opting Out of Background Mode Detecting Multi-Tasking Support Tracking Locations in the Background Making Your Location Apps More Energy Efficient Local Notification Summary 519 519 520 523 5 24 5 24. .. Creating the Application Publishing a Service Browsing for Services Summary 4 41 44 1 44 3 44 6 45 2 Chapter 19: Apple Push Notification Service Generating a Certificate Request 45 5 45 6 xiii www.it-ebooks.info CONTENTS Generating a Development Certificate Creating an Application ID Configuring an App ID for Push Notifications Creating a Provisioning Profile Provisioning a Device Creating the iPhone Application. .. Chapter 16: Web Services 40 3 Basics of Consuming XML Web Services Using SOAP 1.1 Using SOAP 1.2 40 3 40 5 40 6 Consuming a Web Service in Your iPhone Application Parsing the XML Response Summary Chapter 17: Bluetooth Programming 40 7 41 3 41 8 42 1 Using the Game Kit Framework 42 1 Searching for Peer Devices Sending and Receiving Data 42 2 42 9 Implementing Voice Chatting Summary 43 1 43 8 Chapter 18: Bonjour Programming... Appendices Appendix A: Testing on an Actual Device 541 Signing Up for the iPhone Developer Program Obtaining the UDID of Your Device Logging In to the iPhone Provisioning Portal Generating a Certificate Registering Your Devices Creating an Application ID Creating a Provisioning Profile 541 541 542 544 547 548 550 xiv www.it-ebooks.info CONTENTS Understanding Application ID and the Wildcard Preparing for... Invoking SMS 325 325 326 Accessing the Camera and the Photo Library Accessing the Photo Library Accessing the Camera Summary 328 328 337 341 Chapter 14: Recognizing Gestures 343 Recognizing Gestures 343 Tapping Pinching Rotation Panning (or Dragging) 344 349 352 3 54 xii www.it-ebooks.info CONTENTS Swiping Long Press 357 363 Detecting Touches 367 Detecting Single Touch Detecting Multi-Touches Implementing... Table view Chapter 9: Application Preferences discusses the use of application settings to persist application preferences Using application settings, you can access preferences related to your application through the Settings application available on the iPhone and iPad Chapter 10: File Handling shows how you can persist your application data by saving the data to files in your application s sandbox... World! Application Getting Started with Xcode 23 23 Using Interface Builder Writing Some Code 26 31 Customizing Your Application Icon Displaying a Splash Screen Summary Chapter 3: Views, Outlets, and Actions Outlets and Actions Using Views 34 36 39 41 41 47 Using the Alert View Using the Action Sheet Page Control and Image View Using the Web View Adding Views Dynamically Using Code www.it-ebooks.info 48 ... Started with iOS 4 Programming Obtaining the iPhone SDK Components of the iPhone SDK Xcode iPhone Simulator Features of the iPhone Simulator Uninstalling Applications from the iPhone Simulator Interface Builder Instruments Architecture of the iPhone OS Some Useful Information before You Get Started Versions of the iPhone OS Testing on Real Devices Screen Resolutions 3 4 6 6 8 10 11 13 14 14 17 17 18... Image View Using the Web View Adding Views Dynamically Using Code www.it-ebooks.info 48 52 54 62 64 CONTENTS Understanding View Hierarchy Summary 68 70 Chapter 4: View Controllers 73 The View-Based Application Template Editing XIB Files Application Delegate Controlling Your UI Using View Controllers The Window-Based Application Template Adding a View Controller and Views Programmatically Creating and Connecting... 283 2 84 286 288 Bundling SQLite Databases with Your Application Summary 291 292 Part III: Advanced iOS 4 Programming Techniques Chapter 12: Simple Animations and Video Playback Using the NSTimer Class Animating the Visual Change Transforming Views 297 297 3 04 305 Translation Rotation Scaling 305 308 310 Animating a Series of Images Playing Video on the iPhone Summary Chapter 13: Accessing Built-In Applications . 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. 1 047 5 Crosspoint Boulevard. 41 Creating the Application 44 1 Publishing a Service 44 3 Browsing for Services 44 6 Summary 45 2 APPLE PUSH NOTIFICATION SERVICE 45 CHAPTER 19: 5 Generating a Certificate Request 45 6 www.it-ebooks.info xiv CONTENTS Generating. SERVICES 40 CHAPTER 16: 3 Basics of Consuming XML Web Services 40 3 Using SOAP 1.1 40 5 Using SOAP 1.2 40 6 Consuming a Web Service in Your iPhone Application 40 7 Parsing the XML Response 41 3 Summary 41 8 BLUETOOTH

Ngày đăng: 05/05/2014, 13:15

TỪ KHÓA LIÊN QUAN