ios Cloud Development FOR by Neal Goldstein WILEY John Wiley & Sons, Inc.
Table of Contents Introduction 1 About This Book 3 Conventions Used in This Book 3 Foolish Assumptions 4 How This Book Is Organized 5 Part I: Mobile Apps Need to Be Mobile 5 Part II: Adding icloud 5 Part III: Web Services 6 Part IV: Building Your Own Web Service 6 Part V: The Part of Tens 7 Icons Used in This Book 7 Where to Go from Here 7 Part 1: Mobile Apps Need to Be Mobile 9 Chapter 1: Compelling Mobile Applications 11 What Makes Mobile Devices So Compelling 12 Creating zero degrees of separation 13 Benefiting from the mobility, not the mobile devices 13 Increasing the quality of life 14 Making the technology disappear 14 Reveling in the aesthetics 16 An Application Ecosystem 16 icloud and universal apps 18 Web services 18 The Model View Controller (MVC) Architecture 19 Evolving the Model View Controller 21 Chapter 2: The Lonely RoadTrip App 25 Starting at Square 7 26 The RoadTrip App 28 Points of Interest and the Itinerary 36 How RTModel Manages the Data 41
ios Cloud Development For Dummies Part 11: Addinq ictoud. 47 Chapter 3: Setting Up Core Data 49 Managing Your Itinerary 50 Core Data Basics 52 Starting with the Objects The Managed Object Model 53 Adding the attributes 60 Generating your classes 63 Thinking managed objects through 68 The Core Data Stack 69 The managed object context 69 The Persistent Store coordinator and persistent store 70 Adding the Core Data Stack 71 Adding the properties needed by the Core Data stack 71 The managed object context 73 Concurrency support for managed object contexts 75 The Persistent Store coordinator 77 The managed object model 84 Notifications 85 ARC and blocks 88 Adding the Core Data framework 89 Putting Core Data to Work 91 Chapter 4: Putting Core Data to Work 93 Adding a Point of Interest to the Itinerary 94 Adding a Point of Interest to the Itinerary Using Core Data 98 The fetch request 99 Predefining fetch requests in a managed object model 102 Creating a SharedPointOflnterest 105 Displaying Your Itinerary 110 Adding the Fetched Results controller 112 The Fetched Results controller delegate 115 Displaying the SharedPointOflnterests 116 Cleaning Up the ItineraryController and RTModel Classes 120 Loading the Itinerary 122 Timing is Everything 130 Removing a Point Of Interest From the Itinerary 133 How it works now 134 Updating for Core Data 136 Chapter 5: Adding icioud Support 141 icloud Putting icloud to work for you 143 Enter Core Data 144 Setting up Core Data for icloud 146 Handling changes 150 142
Request Response Table of Contents flul Configuring Your App's icloud Entitlements 157 Provisioning Your App for icloud 161 Testing 167 Part 111: Web Services 169 Chapter 6: Living in the Cloud 171 Understanding How Networks Work 172 The Internet 172 The World Wide Web 175 What Exactly Is a Web Service? 176 Message-oriented web services 177 Resource-based web services 177 A Web Service Request 178 It's about client-server 181 And it's about the URL 182 URIor URL? 184 HTTP 185 The HTTP session 186 Initial line 187 Initial line (Status line) 189 Headers 189 An optional message body 190 The RESTful Web Service Architecture 190 REST requirements 192 The rationale behind the requirements 195 It doesn't matter that most web services aren't really RESTful 197 Chapter 7: Exploring an Existing Web Service 199 The Google Geocoding API 200 The request 201 The response 203 Status codes 208 How RoadTrip Currently Does Geocoding 209 Creating the Plumbing: The WSManager 212 Having the Model Use the Geocoding Web Service 221 Chapter 8: Working With XML 229 Parsing the XML Response 229 Putting the parser through its paces 232 The NSXMLParser delegate methods 234 Dealing with errors 238 Good, But Not Good Enough 239
Stateless ios Cloud Development For Dummies Chapter 9: Asynchronous URL Loading 241 Reviewing Your Choices 241 URL Loading System Overview 243 Authentication and credentials 244 Cookie storage 244 Protocol support 244 Using Downloading NSURLConnection data asynchronously 245 Using Web Services Asynchronously 246 Adding the WSLoaderClass '. 247 Using the WSLoader 252 Chapter 10: Adding the JSON Response 261 Working with JSON 261 Parsing the JSON Response 267 Processing a JSON Response 270 There's a Pattern to Using Web Services 286 Add a method to WSManager that makes the request 287 Add a method to WSManager to set up the request 287 Add a method to WSManager to create the NSURLRequest 288 Add a method to YourModel to make the request to the WSManager 289 Adding a method to YourModel that processes the JSON response 290 Putting It All Back Together 291 Part IV: Buitdinq \lour Own Web Service 293 Chapter 11: The RoadTrip Web Services 295 Designing Web Services 295 The Point of a Web Services Architecture 296 Design for extensibility (and change) 297 Optimizing network performance 297 The Basic Model Client Server 298 Making Services Extensible 299 Keep things private with encapsulation 299 Loose coupling 300 Making services cohesive, complete, and non-overlapping 300 Well-Formed Services 301 Services are not functions 301 Services are not methods 302 The Resource 303
Table of Contents The Response 304 Limiting Unauthorized Web Service Use 305 Designing a Web Service 305 The pointsofinterest Web Service 308 The request 308 The response 308 The lastupdate Web Service 309 The request 309 The response 309 The allpointsofinterest Web Service 310 The request 310 The response 310 The addpointofinterest Web Service 311 The request 311 The response 312 The deletepointofinterest Web Service 312 The request 312 The response 313 Additional Error Considerations 313 Chapter 12: The App Engine Implementation 315 Google App Engine 315 The application environment 315 How App Engine works 316 App Engine SDKs 320 Using Python with App Engine 321 What You Need to Develop for App Engine 322 The webapp2 Starter Kit 333 The webapp Framework 337 Now a little about Python 339 And more on routing 340 Handling handlers 341 A little more Python 345 The Model Application Controller Architecture in App Engine 347 Chapter 13: The Model s Model 351 What's in the Model? 351 The App Engine Datastore 353 The webapp Model classes 354 Adding a method to the model 358 The TestData Class 363 Testing in Your Browser 370
ios Cloud Development For Dummies Chapter 14: Creating and Using the pointsofmterest Web Service 373 The pointsofinterest Web Service 373 Updating RoadTrip 383 Setting up the WSManager methods to make the request and do the setup 384 Adding the RTModel methods to make the request and process the JSON response 388 Adding the required Send the new message 395 methods to PointOflnterest 393 Using Cached Data 396 Adding the UpdateRecord model 397 Updating RoadTrip to use cached data 402 Keeping the Points Of Interest Current 409 Chapter 15: Deploying Your Web Services 411 Cleaning Up Your App 411 Transmitting Data Securely Across the Network 412 Storing Data Securely 416 Deploying rtpointsofinterest to Google App Engine 417 What's Next 419 Part V: The Part of Tens.. 421 Chapter 16: Ten Ways to Extend the RoadTrip App 423 Dealing with Errors 423 Make Events a Web Service 424 Expand the Point of Interest Data 424 Crowd Source Points of Interest 424 Cache Data 424 Post to Facebook and Twitter 424 Send Postcards from the Road 425 Add Hotels and Reservations 425 It's Never Early Enough to Start Speaking a Foreign Language 425 In the Road Trip Editor 425 Chapter 17: Ten Ways to Be a Happy Developer 427 Keep Things Loosely Coupled 427 Remember Memory 428 Don't Reinvent the Wheel 428 Understand State Transitions 429 Do the Right Thing at the Right Time 430 Avoid Mistakes in Error Handling 431
Table of Contents Use Storyboards 431 Remember the User 431 Keep in Mind that the Software Isn't Finished Until the Last User Is Dead 432 Keep It Fun 432 Bonus Chapter: Adding and Deleting Points of Interest Implementing Yet More Web Services BC2 The Road Trip Editor App Using the addpointofinterest Web Service in Road Trip Editor The deletepointofinterest Web Service BC20 Implementing DELETE in Road Trip Editor BC23 BC1 BC6 BC11 Index 433