ios in Practice BEAR CAHILL if MANNING Shelter Island
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 O Creating an ios application 14-4ot"/ 2.1 Source code files 15 2.2 Adding a button to your app 16 2.3 Connecting your 2.4 Connecting your button to an action 17 label as an outlet 18 2.5 Implementing your button action 19 2.6 Delegation 20 2.7 Summary 20
X CONTENTS Part 2 Putting ios into practice 21 5Using view controllers and images 3.1 UI design concepts 24 in PicDecor 23 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 27 Technique 1 Designing a view controller with IB 27 Technique 2 Adding an Image View and toolbar to a view 32 Technique 3 Adding 3.3 Developing buttons to a view 36 actions and outlets 37 Technique 4 Declaring actions and outlets in Xcode 37 Technique 5 Connecting 3.4 Using the camera/photo actions and outlets to code 41 album 45 Technique 6 Adding camera/photo album access 46 Technique 7 Presenting a view controller modally 48 Technique 8 Dismissing a modally displayed view controller 49 3.5 Displaying and handling images 50 Interact with the process as it goes 51 Technique 9 Displaying selected images 51 Technique 10 Detecting a device without a camera 53 3.6 Providing email capabilities 54 Technique 11 Adding in-app email 54 Technique 12 Scaling an image for email 57 Technique 13 Using the activity indicator 57 3.7 Summary 58 Accessing the address book/contacts in DiaH 60 4.1 Creating a master-detail application with a table view 61 Technique 14 Creating a master-detail application 61 4.2 Presenting data using Technique 15 Displaying a table view 63 data in a table view 64 Apple cell styles 66 Cell customization 66 Technique 16 Handling table view cell selection 67 4.3 Accessing the address book 68 Technique 17 Retrieving the address book entries 69 Technique 18 Obtaining address book image property 71 Technique 19 Obtaining grouped properties book 72 from the address
CONTENTS Technique 20 Making Technique 21 Displaying 4.4 Managing table data 80 a call 74 address book record details 76 Technique 22 Deleting and rearranging table view rows 81 Technique 23 Filtering displayed table view data 83 4.5 Summary 85 MapKit and the camera in WherelsMyCar 87 5.1 Using maps with the user's location 89 Technique 24 Adding a MapView to a project 89 Technique 25 Centering and zooming a MapView 91 Technique 26 Finding the user's location via CoreLocation 93 5.2 Displaying details on MapView locations and storing user's notes 94 Technique 27 Displaying MapView pins 95 Technique 28 Storing and retrieving the user's location 98 Technique 29 Reverse geocoding 100 Technique 30 Adding pin callouts 101 Technique 31 Typing and storing user's note 104 5.3 Storing, retrieving, and displaying camera images 107 Technique 32 Adding a camera control 108 Technique 33 Receiving and storing the picture 110 Technique 34 Displaying a picture 112 5.4 Summary 113 Settings, audio, and shake detection in TimeDoum 114 6.1 Settings bundle in ios projects 116 Technique 35 Adding settings to an Xcode project 116 Technique 36 Initializing ios settings 118 Technique 37 Accessing settings values in an app 119 Technique 38 Setting the app settings icon 120 6.2 Runtime and time-based UI changes 122 Technique 39 Rounding corners of a view 122 Technique 40 Updating the UI with a repeating timer 124 6.3 Playing audio and vibrating the device 125 Technique 41 Playing an MP3 file 126 Technique 42 Vibrating the iphone 127 6.4 Detecting and handling device motion 128 Technique 43 Detecting shaking with the accelerometer 128 Technique 44 Handling shaking with an action sheet 129 6.5 Summary 131
CONTENTS CoreData, ipod access, and playing music PlayMyLists 132 7.1 Creating a table view project 133 Technique 45 Create a project with table navigation 133 Technique 46 Defining entities in CoreData 135 Technique 47 Creating relationships in CoreData 137 Technique 48 Inserting and deleting CoreData objects 139 Technique 49 Creating classes for CoreData entities 141 7.2 Displaying CoreData for data-driven apps 143 Technique 50 Display selected item details 143 Technique 51 Passing a Playlist to the Detail View controller 144 Technique 52 Replacing the detail view controller 146 Technique 53 Managing tracks in the selected playlist 147 7.3 Accessing ipod music 148 Technique 54 Using the media picker to access music 148 Technique 55 Finding media info from the ipod 151 7.4 Playing music with ios 152 Technique 56 Playing the playlist 153 Technique 57 Handling music player updates 154 7.5 Summary 156 Push notification and in-app purchase Rock, Paper, Scissors 157 8.1 Using Apple Push Notification 158 Technique 58 Provisioning for push notification 158 Technique 59 Configuring UrbanAirship for APN 161 Technique 60 Registering your app for push notifications 164 Technique 61 Registering your app with UrbanAirship 165 Technique 62 Sending a batch push 8.2 In-app purchase 170 notification 167 Technique 63 Setting up itunesconnect for in-app purchase 171 Technique 64 Creating an in-app test account 174 Technique 65 Adding in-app purchases to the project 175 8.3 The Rock, Paper, Scissors game 178 Technique 66 Designing the game 178 Technique 67 Overturning a loss 182 8.4 Summary 183
CONTENTS GameCenter leaderboards and achievements Rock, Paper, Scissors 184 9.1 Game Center authentication and leaderboards 185 Technique 68 Authenticating the player 185 Technique 69 Configuring leaderboards in itunesconnect \i Technique 70 Saving the player's score 188 Technique 71 Displaying the leaderboard 190 9.2 GameCenter achievements 192 Technique 72 Adding an achievement in itunesconnect 192 Technique 73 Reporting achievement progress 193 Technique 74 Displaying achievement boards 195 9.3 Matching and playing via GameCenter 196 Technique 75 Matching players 196 Technique 76 Inviting friends to play 200 Technique 77 Voice chat via the GameCenter 204 9.4 Summary 205 itunes API, ipad, and iad MusicSearch 206 10.1 Searching for music with the itunes API 207 Technique 78 Querying with the itunes API 207 Technique 79 DisplayingJSON results 209 Technique 80 Playing song preview 211 10.2 Converting an app to ipad 213 Technique 81 Converting the project in Xcode 214 Technique 82 Adding a split view to the app 218 Technique 83 Displaying items in the detail view 224 10.3 Adding iads to an app 226 Technique 84 Configuring itunes for iads 226 Technique 85 10.4 Summary 229 Adding iads to an app Collection view, social, reminders, and state restoration MeetSocial 230 227 11.1 Presenting data using a collection view 231 Technique 86 Creating a project to use a collection view 231 Technique 87 Fetching search results from Meetup.com 235 Technique 88 Displaying items in a collection view 237
xiv CONTENTS 11.2 Sharing via the Social Framework 242 Technique 89 Specifying activity items 243 Technique 90 Presenting the activity sharing interface 245 11.3 Creating calendar items in the OS 246 Technique 91 Creating Technique 92 Creating a calendar reminder 250 11.4 Saving and restoring the event store and calendar event 246 the UI state 252 Technique 93 Specify that an app will save/restore 252 Technique 94 Setting restoration IDs on objects 253 Technique 95 Assigning restoration classes 254 Technique 96 Encode/decode Ul-related state values 255 Technique 97 Table/collection datasource considerations 257 Technique 98 Additional app 11.5 Summary 259 version and state data 258 appendix The ios developer program and app distribution 260 index 275