ebook img

iPhone Advanced Projects PDF

394 Pages·1996·5.91 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 iPhone Advanced Projects

Cyan yelloW spoT MaTTe MaGenTa BlaCk panTone 123 C Books for professionals By professionals® Companion eBook Available T Development Tales of he apress series of iphone projects books features experienced app develop- ers presenting their own work in their own words. you get firsthand accounts i iPhone App Masters of what it takes to design, implement, and launch some of the finest applications P available from apple’s iTunes app store. h iPhone Advanced Projects, the third book in this series, tackles some advanced as- pects of iphone development. The first generation of iphone applications has hit the o app store, and now it’s time to optimize performance, streamline the user interfaces, and make every successful iphone app just that much more sophisticated. n your guides for this exploration of the next level of iphone development include the e following: • Ben Britten Smith, discussing particle systems using openGl es A • Joachim Bondo, demonstrating his implementation of correspondence gaming in the most recent version of his chess application, Deep Green d • Tom Harrington, implementing streaming audio with Core audio, one of v many iphone os 3 apis • Owen Goss, debugging those pesky errors in your iphone code with an eye a toward achieving professional-strength results • n Dylan Bruzenak, building a data-driven application with sQlite • Ray Kiddy, illustrating the full application development life cycle with c Core Data e • Steve Finkelstein, marrying an offline e-mail client to Core Data • d Peter Honeder and Florian Pflug, tackling the challenges of networked applications in Wifi environments • Jonathan Saggau, improving interface responsiveness with some of his P iPhone personal tips and tricks, including “blocks” and other esoteric techniques • r Joe Pezzillo, pushing the frontiers of iphone os 3’s new apple push notification service (apns) that makes the cloud the limit for iphone apps o • Noel Llopis, taking mere programmers on a really advanced developmental j adventure into the world of environment mapping with openGl es e S Advanced Projects e l it’s a full banquet of treats, so dig in where the morsels look most tempting. There’s t c ti plenty here for every palate. apress also offers a nourishing first course with its ed best-selling Beginning iPhone 3 Development: Exploring the iPhone SDK. and we’re t t la always on the lookout for what’s new and even tastier, so feel free to share your s e r most nourishing apps with us. We’d love to be able to add them to the next volume of iphone projects. Joachim Bondo  |  Dylan Bruzenak  |  Steve Finkelstein  |  Owen Goss    This book is for all iphone application developers with any level of experience or com- ing from any development platform who wants to see how an advanced app is made. Tom Harrington  |  Peter Honeder  |  Florian Pflug  |  Ray Kiddy  Take what you learn in this book and use it to create the next great iphone app! Noel Llopis  |  Joe Pezzillo  |  Jonathan Saggau  |  Ben Britten Smith  Companion eBook See laSt page for detailS on $10 eBook verSion ISBN 978-1-4302-2403-7 Preface by Glenn Cole 53999 US $39.99 shelve in Mobile Computing/Mac programming SOURCE CODE ONLINE User level: www.apress.com intermediate 9 781430 224037 this print for content only—size & color not accurate spine = 0.875 " 392 page count Download at WoweBook.Com iPhone Advanced Projects ■■■ Dave Mark, Series Editor Joachim Bondo Ray Kiddy Dylan Bruzenak Noel Llopis Steve Finkelstein Joe Pezzillo Owen Goss Florian Pflug Tom Harrington Jonathan Saggau Peter Honeder Ben Britten Smith Download at WoweBook.Com iPhone Advanced Projects Copyright © 2009 by Dave Mark, Joachim Bondo, Dylan Bruzenak, Steve Finkelstein, Owen Goss, Tom Harrington, Peter Honeder, Ray Kiddy, Noel Llopis, Joe Pezzillo, Florian Pflug, Jonathan Saggau, Ben Britten Smith All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. ISBN-13 (pbk): 978-1-4302-2403-7 ISBN-13 (electronic): 978-1-4302-2404-4 Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1 Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. Lead Editor: Clay Andres Technical Reviewer: Glenn Cole Developmental Editor: Douglas Pundick Editorial Board: Clay Andres, Steve Anglin, Mark Beckner, Ewan Buckingham, Tony Campbell, Gary Cornell, Jonathan Gennick, Michelle Lowman, Matthew Moodie, Jeffrey Pepper, Frank Pohlmann, Ben Renow- Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh Coordinating Editor: Kelly Moritz Copy Editor: Kim Wimpsett Compositor: MacPS, LLC Indexer: Julie Grady Artist: April Milne Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, e-mail [email protected], or visit http://www.springeronline.com. For information on translations, please e-mail [email protected], or visit http://www.apress.com. Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Special Bulk Sales– eBook Licensing web page at http://www.apress.com/info/bulksales. The information in this book is distributed on an “as is” basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work. The source code for this book is available to readers at http://www.apress.com. You will need to answer questions pertaining to this book in order to successfully download the code. 2ii Download at WoweBook.Com To my lovely wife, Leonie. —Ben Britten Smith To my wife, Malena, who once again gave me the support I hadn’t earned. —Joachim Bondo To everyone I know and to everyone I haven’t met yet. —Dylan Bruzenak To all of my family and friends for their support and patience with my demanding schedule. To my loving wife, Michelle, who sustains me and encourages me to take risks. Finally, this one is for my grandmother, Asya; you will live forever in all our hearts. —Steve Finkelstein To the iPhone game developers on Twitter for sharing so much and being such a supportive community. —Noel Llopis (@snappytouch on Twitter) I’m so grateful to so many people I can’t possibly hope to name them all individually, so, en masse, let me thank the blessing that is my family (especially my son), the unstoppable geniuses at Apple, the folks at Apress who patiently awaited my writing, the incredibly supportive Mac and iPhone indie developer community, all my clients and customers, my business partners and colleagues, and, of course, the great ineffable spirit of the universe that makes everything possible. Thank you! —Joe Pezzillo To my family, my friends, the island “La Palma,” and the one who introduced me to it. —Florian Pflug To Dr. Michele, who doesn’t let me call her doctor. Thanks for making me type. —Jonathan Saggau iii Download at WoweBook.Com Contents at a Glance ■Contents at a Glance ................................................................................................................................................................ iv ■Contents .................................................................................................................................................................................... v ■Foreword ................................................................................................................................................................................. xi ■About the Technical Reviewer ................................................................................................................................................ xii ■Preface ................................................................................................................................................................................... xiii Ben Britten Smith ........................................................................................................................................................................ 1 ■Everything You Ever Wanted to Know About Particle Systems ................................................................................................ 3 Joachim Bondo .......................................................................................................................................................................... 37 ■Chess on the ’Net: Correspondence Gaming with Deep Green ................................................................................................ 39 Tom Harrington .......................................................................................................................................................................... 63 ■Audio Streaming: An Exploration into Core Audio .................................................................................................................. 65 Owen Goss ................................................................................................................................................................................. 99 ■You Go Squish Now! Debugging on the iPhone ..................................................................................................................... 101 Dylan Bruzenak ........................................................................................................................................................................ 139 ■Building Data-Driven Applications with Active Record and SQLite ...................................................................................... 141 Ray Kiddy ................................................................................................................................................................................. 181 ■Core Data and Hard-Core Design .......................................................................................................................................... 183 Steve Finkelstein ..................................................................................................................................................................... 209 ■Smart In-Application E-mail with Core Data and Three20 ................................................................................................... 211 Florian Pflug and Peter Honeder .............................................................................................................................................. 247 ■How iTap Tackles the Challenges of Networking .................................................................................................................. 249 Jonathan Saggau ..................................................................................................................................................................... 277 ■Fake It ’Til You Make It: Tips and Tricks for Improving Interface Responsiveness .............................................................. 279 Joe Pezzillo .............................................................................................................................................................................. 311 ■Demystifying the Apple Push Notification Service ............................................................................................................... 313 Noel Llopis ............................................................................................................................................................................... 345 ■Environment Mapping and Reflections with OpenGL ES ...................................................................................................... 347 ■Index ..................................................................................................................................................................................... 365 4iv Download at WoweBook.Com Contents ■Contents at a Glance ............................................................................................................... iv(cid:3) ■Contents .................................................................................................................................. v(cid:3) ■Foreword ................................................................................................................................ xi(cid:3) ■About the Technical Reviewer ............................................................................................... xii ■Preface ................................................................................................................................. xiii Ben Britten Smith ....................................................................................................................... 1(cid:3) ■CHAPTER 1: Everything You Ever Wanted to Know About Particle Systems .................................................................................................... 3(cid:3) Adding Life to Your Game with Particles ..................................................................................................................................................5 Basic Particle Systems and You ...............................................................................................................................................................7 Overview of the Sample Code .............................................................................................................................................................8 Basic Game Flow .................................................................................................................................................................................9 The Anatomy of a Particle System ....................................................................................................................................................10 Code! Finally! ....................................................................................................................................................................................12 Slight Tangent About Degenerates ....................................................................................................................................................15 Back to the Code ...............................................................................................................................................................................16 Random Numbers and Initial Conditions ...........................................................................................................................................19 Emitting Particles ..............................................................................................................................................................................20 Tweaking Your Particle System .............................................................................................................................................................21 May the Force Be with Your Particles ...............................................................................................................................................25 Amazing Technicolor Dream Particle .....................................................................................................................................................28 Off on a Tangent: Lerping ..................................................................................................................................................................28 Color-Changing Particles ...................................................................................................................................................................30 Summary ................................................................................................................................................................................................35 v Download at WoweBook.Com ■ CONTENTS Joachim Bondo.........................................................................................................................37(cid:3) ■Chapter 2: Chess on the ’Net: Correspondence Gaming with Deep Green................................................................................................39(cid:3) Deep Green, an Already Awesome Application......................................................................................................................................40 The Tasks at Hand..................................................................................................................................................................................42 Inviting a Friend to a Game...............................................................................................................................................................43 Accepting the Invitation....................................................................................................................................................................43 Making a Move..................................................................................................................................................................................43 Getting Notified.................................................................................................................................................................................43 The Tools of the Trade............................................................................................................................................................................44 Stop Talking, Start Coding!....................................................................................................................................................................45 Installing the Tools............................................................................................................................................................................45 Coding the Web Service....................................................................................................................................................................47 Accepting the Challenge on the Device.............................................................................................................................................54 Making a Move..................................................................................................................................................................................57 Summary................................................................................................................................................................................................61 Tom Harrington........................................................................................................................63(cid:3) ■Chapter 3: Audio Streaming: An Exploration into Core Audio...............................................65(cid:3) Hey, I Could Write an App to Play Music................................................................................................................................................66 MPMoviePlayerController: Hey, This Is Easy! Right?..............................................................................................................................66 Finding a Better Approach......................................................................................................................................................................68 The System-Sound Way....................................................................................................................................................................69 AVAudioPlayer: The Not-Available-in-Beta Way................................................................................................................................69 Doing It the Cowboy Way with Core Audio.............................................................................................................................................74 Getting Halfway There: Audio Queue Services..................................................................................................................................74 Getting the Rest of the Way There: Audio File Stream Services........................................................................................................81 Putting It All into an App.........................................................................................................................................................................93 One More Thing.................................................................................................................................................................................93 Launch It!...............................................................................................................................................................................................96 iPhone 3.0 and Further Work.................................................................................................................................................................96 Summary................................................................................................................................................................................................97 Owen Goss................................................................................................................................99(cid:3) ■Chapter 4: You Go Squish Now! Debugging on the iPhone..................................................101(cid:3) Assumed Knowledge............................................................................................................................................................................102 Objective-C vs. C and C++...................................................................................................................................................................104 While You’re Writing That Code............................................................................................................................................................105 Custom Asserts...............................................................................................................................................................................105 Custom Logging..............................................................................................................................................................................107 Using #define..................................................................................................................................................................................108 Crash!...................................................................................................................................................................................................109 Getting a Crash Log from Your Testers...........................................................................................................................................109 You Have Been Saving Your dSYM Files, Right?.............................................................................................................................110 Symbolicatinga Crash Log..............................................................................................................................................................110 6vi Download at WoweBook.Com ■ CONTENTS Using atos.......................................................................................................................................................................................111 Reproducing Rare Crashes...................................................................................................................................................................112 Thread.............................................................................................................................................................................................112 System............................................................................................................................................................................................113 Race Conditions..............................................................................................................................................................................113 The Scientific Method of Debugging....................................................................................................................................................113 Forming a Hypothesis.....................................................................................................................................................................113 Creating a Test for Your Hypothesis................................................................................................................................................114 Proving or Disproving Your Hypothesis...........................................................................................................................................115 Increasing the Probability of the Crash...........................................................................................................................................115 So, You Have a Call Stack....................................................................................................................................................................115 Starting Code...................................................................................................................................................................................115 What Is a Memory Stomp?..............................................................................................................................................................118 Identifying a Mem Stomp................................................................................................................................................................122 Tools to Detect Memory Problems..................................................................................................................................................123 Watching Variables.........................................................................................................................................................................131 Link Map Files.................................................................................................................................................................................135 Summary..............................................................................................................................................................................................137 Dylan Bruzenak......................................................................................................................139(cid:3) ■Chapter 5: Building Data-Driven Applications with Active Record and SQLite.............................................................................................141(cid:3) A Short Road Off a High Cliff (How I Got Here)....................................................................................................................................141 Ready! Set! Wait, What? (Why I Decided to Write a To-Do Application)...............................................................................................142 Data-Driven Applications on the iPhone...............................................................................................................................................143 Active Record: A Simple Way of Accessing Data................................................................................................................................144 Writing a Database Wrapper Around the C API: ISDatabase................................................................................................................144 Setting Up the Example Project.......................................................................................................................................................145 Creating and Initializing the Database............................................................................................................................................148 Opening a Database Connection.....................................................................................................................................................149 Making Simple Requests.................................................................................................................................................................152 More Advanced SQL.............................................................................................................................................................................158 Preventing Duplicate Create Statements........................................................................................................................................158 Handling Parameters.......................................................................................................................................................................160 Refactoringand Cleanup.................................................................................................................................................................162 Grouping Statements into Transactions..........................................................................................................................................163 Writing a Simple Active Record Layer: ISModel...................................................................................................................................164 Maintaining the Database Connection............................................................................................................................................165 The Model Object: Grocery Item......................................................................................................................................................165 How Groceries Are Mapped.............................................................................................................................................................166 Saving.............................................................................................................................................................................................168 Updating..........................................................................................................................................................................................170 Deleting...........................................................................................................................................................................................170 Finding Grocery Items.....................................................................................................................................................................171 Putting It All Together......................................................................................................................................................................174 vii Download at WoweBook.Com ■ CONTENTS Simple Migration Handling...................................................................................................................................................................176 Alternative Implementations................................................................................................................................................................179 Summary..............................................................................................................................................................................................180 Ray Kiddy...............................................................................................................................181(cid:3) ■Chapter 6: Core Data and Hard-Core Design.......................................................................183(cid:3) Where Did Core Data Come From?.......................................................................................................................................................184 The Client Is King............................................................................................................................................................................184 A Very First Core Data App...................................................................................................................................................................185 First, Steal Code (Not Music!)..........................................................................................................................................................186 A View to an Object, Any Object......................................................................................................................................................187 Our Very First Crash, or Perhaps Not!.............................................................................................................................................193 CoreData Tutorial for iPhone OS: Managing Model Migrations............................................................................................................194 The Easy Migrations Are Easy.........................................................................................................................................................194 Adding a New Entity........................................................................................................................................................................197 Using Key-Value Coding to Create a Reusable Object..........................................................................................................................199 Remote Databases: It’s All Net!............................................................................................................................................................203 Summary..............................................................................................................................................................................................206 Steve Finkelstein....................................................................................................................209(cid:3) ■Chapter 7: mart In-Application E-mail with Core Data and Three20.................................................................................................211(cid:3) Planning a Simple Offline SMTP Client.................................................................................................................................................212 Creating the User Interface..................................................................................................................................................................213 Diving into Xcode............................................................................................................................................................................213 Setting Up Instance Variables in OfflineMailerAppDelegate.h.........................................................................................................215 Initializing the UIApplication Delegate.............................................................................................................................................217 Working with Core Data.......................................................................................................................................................................218 Understanding the Core Data Stack................................................................................................................................................221 Adding Three20...............................................................................................................................................................................221 Journeying Through the User Interface................................................................................................................................................224 Managing Top-Level Data with DataManager......................................................................................................................................226 Diving into Three20 and TTMessageController....................................................................................................................................228 Composing and Sending Messages.....................................................................................................................................................230 Creating the Core Data Model..............................................................................................................................................................235 Hacking SKPSMTPMessage to Support Threaded Message Sending..................................................................................................239 Setting Up the NSRunLoop on SKPSMTPMessage...............................................................................................................................239 Switching the Bits Back to Online Mode..............................................................................................................................................241 Summary..............................................................................................................................................................................................244 Florian Pflug and Peter Honeder............................................................................................247(cid:3) ■Chapter 8: How iTap Tackles the Challenges of Networking...............................................249(cid:3) Meet iTap and iTap Receiver................................................................................................................................................................250 iTap.................................................................................................................................................................................................251 iTap Receiver...................................................................................................................................................................................251 How the Idea for iTap Emerged and Evolved.......................................................................................................................................252 8viii Download at WoweBook.Com

Description:
As the fourth book in our series of iPhone Projects based on the work and experiences of iPhone, this volume takes on the more advanced aspects of iPhone development. The first generation of iPhone applications has hit the App Store, and now it's time to optimize performance, streamline the user int
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.