Bear Cahill Includes 98 Techniques Covers iOS 6 MANNING iOS in Practice iOS in Practice BEAR CAHILL MANNING SHELTER ISLAND For online information and ordering of this and other Manning books, please visit www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact Special Sales Department Manning Publications Co. 20 Baldwin Road PO Box 261 Shelter Island, NY 11964 Email: orders@manning.com ©2013 by Manning Publications Co. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps. Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without the use of elemental chlorine. Manning Publications Co. Development editor: Scott Meyers 20 Baldwin Road Technical proofreader: James Hathewa y PO Box 261 Copyeditors: Linda Kern, Benjamin Berg Shelter Island, NY 11964 Proofreaders: Katie Tennant, Alyson Brener Typesetter: Dottie Marsico Cover designer: Marija Tudor ISBN 9781617291265 Printed in the United States of America 1 2 3 4 5 6 7 8 9 10 – MAL – 17 16 15 14 13 12 To Kelly Ripa, who brightens my wife’s day, who in turn brightens mine vii brief contents PART 1 GETTING STARTED 1 1 ■ Getting started with iOS development 3 2 ■ Creating an iOS application 14 PART 2 PUTTING IOS INTO PRACTICE 21 3 ■ Using view controllers and images in PicDecor 23 4 ■ Accessing the address book/contacts in Dial4 60 5 ■ MapKit and the camera in WhereIsMyCar 87 6 ■ Settings, audio, and shake detection in TimeDown 114 7 ■ CoreData, iPod access, and playing music—PlayMyLists 132 8 ■ Push notification and in-app purchase—Rock, Paper, Scissors 157 9 ■ GameCenter leaderboards and achievements—Rock, Paper, Scissors 184 10 ■ iTunes API, iPad, and iAd—MusicSearch 206 11 ■ Collection view, social, reminders, and state restoration— MeetSocial 230 ix contents preface xv acknowledgments xvi about this book xvii about the cover illustration xx PART 1 GETTING STARTED 1 1 Getting started with iOS development 3 1.1 The iOS development environment 4 1.2 Using Xcode 4 Getting Xcode 5 ■ Tour of Xcode 5 1.3 A quick Hello World app 8 Creating a New Project 8 ■ Editing the user interface 10 1.4 Summary 13 2 Creating an iOS application 14 2.1 Source code files 15 2.2 Adding a button to your app 16 2.3 Connecting your button to an action 17 2.4 Connecting your label as an outlet 18 2.5 Implementing your button action 19 2.6 Delegation 20 2.7 Summary 20 [...]... Summary Adding a MapView to a project 89 Centering and zooming a MapView 91 Finding the user’s location via CoreLocation 93 Displaying details on MapView locations and storing user’s notes 94 Displaying MapView pins 95 Storing and retrieving the user’s location Reverse geocoding 100 Adding pin callouts 101 Typing and storing user’s note 104 Summary Adding a camera control 108 Receiving and storing the... PUTTING IOS INTO PRACTICE 21 Using view controllers and images in PicDecor 23 3.1 UI design concepts 24 Building blocks that can be customized 25 Product definition statement 26 Thinking outside the box 26 Think Apple 27 ■ ■ 3.2 Creating view controllers and other widgets TECHNIQUE 1 TECHNIQUE 2 TECHNIQUE 3 3.3 Designing a view controller with IB 27 Adding an ImageView and toolbar to a view Adding... 110 Displaying a picture 112 113 Settings, audio, and shake detection in TimeDown 6.1 Settings bundle in iOS projects TECHNIQUE 35 TECHNIQUE 36 TECHNIQUE 37 TECHNIQUE 38 6.2 122 Rounding corners of a view 122 Updating the UI with a repeating timer 124 Playing an MP3 file 126 Vibrating the iPhone 127 Detecting and handling device motion TECHNIQUE 43 TECHNIQUE 44 6.5 116 Playing audio and vibrating the... device 125 TECHNIQUE 41 TECHNIQUE 42 6.4 114 Adding settings to an Xcode project 116 Initializing iOS settings 118 Accessing settings values in an app 119 Setting the app settings icon 120 Runtime and time-based UI changes TECHNIQUE 39 TECHNIQUE 40 6.3 98 Storing, retrieving, and displaying camera images 107 TECHNIQUE 32 TECHNIQUE 33 TECHNIQUE 34 5.4 87 Using maps with the user’s location 89 TECHNIQUE... controller Replacing the detail view controller 146 Managing tracks in the selected playlist 147 Accessing iPod music TECHNIQUE 54 TECHNIQUE 55 7.4 Create a project with table navigation 133 Defining entities in CoreData 135 Creating relationships in CoreData 137 Inserting and deleting CoreData objects 139 Creating classes for CoreData entities 141 Summary Playing the playlist 153 Handling music player... This book is organized into two parts Part one talks about iOS development in general How to get started, the frameworks provided by Apple, the Provisioning Portal, the IDE, and several core concepts are introduced in this first part of the book The second part includes techniques for putting iOS development into practice The chapters in part 2 contain projects that are developed using multiple techniques... core aspects—it covers iOS development both in general and in practice Learning happens best through examples and exercises‚ as opposed to learning about theories or concepts in isolation So I’ve included numerous hands-on techniques and examples to get you started in iOS development About the author Bear Cahill has worked in iOS development at Brainwash Inc since 2008 and through the development of several... 196 Matching players 196 Inviting friends to play 200 Voice chat via the GameCenter iTunes API, iPad, and iAd—MusicSearch 10.1 187 192 Adding an achievement in iTunesConnect Reporting achievement progress 193 Displaying achievement boards 195 Matching and playing via GameCenter TECHNIQUE 75 TECHNIQUE 76 TECHNIQUE 77 185 Authenticating the player 185 Configuring leaderboards in iTunesConnect Saving the... you’ll also see information about joining the various developer programs such as Safari, iOS, and Mac In most cases, the developer programs cost money to join, but they also allow access to advance/beta releases, developer forums, and other resources If you intend to do much iOS development, I highly recommend joining If you intend to release any apps, you have to join Now that you have Xcode installed,... MainStoryboard because you chose to use the Storyboard setting during your app creation If you hadn’t checked that box, this setting would be empty and you’d have a Main Interface setting instead The default Main Interface settings would relate to a UI design file with the file extension of xib Instead, you have a storyboard file in your project Most of the projects in this book use XIB files for UI design, but . Bear Cahill Includes 98 Techniques Covers iOS 6 MANNING iOS in Practice iOS in Practice BEAR CAHILL MANNING SHELTER ISLAND For online information and ordering of this and other Manning books,. in turn brightens mine vii brief contents PART 1 GETTING STARTED 1 1 ■ Getting started with iOS development 3 2 ■ Creating an iOS application 14 PART 2 PUTTING IOS INTO PRACTICE 21 3 ■ Using. PUTTING IOS INTO PRACTICE 21 3 Using view controllers and images in PicDecor 23 3.1 UI design concepts 24 Building blocks that can be customized 25 ■ Product definition statement 26 ■ Thinking