With Advanced iOS 4 Programming , developers have the expert guidance they need to create amazing applications for Apple’s iPhone®, iPad®, and iPod® touch. Inside, veteran mobile developer Dr. Maher Ali begins with a foundation introduction to Objective C and Cocoa Touch programming, and then guides readers through building apps with Apple’s iPhone SDK 4 – including coverage of the major categories of new APIs and building apps for the new Apple iPad®. This book concentrates on illustrating GUI concepts programmatically, allowing readers to fully appreciate the complete picture of iOS 4 development without relying on Interface Builder. In addition, Interface Builder is covered in several chapters. Advanced iOS 4 Programming delves into more advanced topics going beyond the basics of iOS 4 development, providing comprehensive coverage that will help you get your apps to the App Store quicker. Key features include: Objective-C programming language and runtime Interface Builder Building advanced mobile user interfaces Collections Cocoa Touch Core Animation and Quartz 2D Model-view-controller (MVC) designs Developing for the iPad Grand Central Dispatch Parsing XML documents using SAX, DOM, and TouchXML Working with the Map Kit API Remote and Local Push Notification Blocks (closures) in Objective-C Building advanced location-based applications Developing database applications using the SQLite engine GameKit framework Advanced iOS 4 Programming......Page 1 Contents......Page 5 Preface......Page 16 Publisher’s Acknowledgments......Page 23 1.1.2 Creating a project......Page 25 1.1.3 Familiarizing yourself with the IDE......Page 27 1.1.4 Looking closely at the generated code......Page 28 1.2.1 Interface Builder......Page 30 1.2.2 Revising the application......Page 33 1.3 Using the Debugger......Page 38 1.4 Getting More Information......Page 40 1.5 Summary......Page 41 Exercises......Page 42 2.1 Classes......Page 43 2.1.1 Class declaration......Page 44 2.1.3 Class definition......Page 45 2.1.4 Method invocation and definition......Page 46 2.1.6 Important Cocoa classes......Page 47 2.2.1 Creating and deallocating objects......Page 48 2.2.2 Preventing memory leaks......Page 49 2.3 Protocols......Page 51 2.4.1 Property declaration......Page 53 2.4.2 Circular references......Page 57 2.5 Categories......Page 60 2.6 Posing......Page 61 2.7.1 Exceptions......Page 62 2.7.2 Errors......Page 66 2.8 Key-Value Coding (KVC)......Page 68 2.8.1 An example illustrating KVC......Page 69 2.8.2 KVC in action......Page 70 2.9 Multithreading......Page 75 2.10 Notifications......Page 78 2.11.1 Declaration and definition......Page 80 2.11.3 Invocation......Page 81 2.11.4 Variable binding......Page 82 2.12.1 Queues......Page 83 2.12.3 Putting it together......Page 84 2.13 The Objective-C Runtime......Page 85 2.13.2 The NSObject class......Page 86 2.13.3 Objective-C methods......Page 87 2.13.4 Examples......Page 90 2.14 Summary......Page 106 Exercises......Page 107 3.1 Arrays......Page 111 3.1.1 Immutable copy......Page 113 3.1.2 Mutable copy......Page 115 3.1.3 Deep copy......Page 117 3.1.4 Sorting an array......Page 120 3.2.1 Immutable sets......Page 125 3.2.2 Mutable sets......Page 126 3.3 Dictionaries......Page 128 3.4 Summary......Page 130 Exercises......Page 131 4.1.1 Create a main.m file......Page 133 4.1.2 Create the application delegate class......Page 134 4.1.3 Create the user interface subclasses......Page 135 4.2 Building the Hello World Application......Page 136 4.3 Summary......Page 140 Exercises......Page 141 5.1.1 Useful geometric type definitions......Page 143 5.1.2 The UIScreen class......Page 144 5.1.3 The frame and center properties......Page 145 5.1.4 The bounds property......Page 147 5.2 The View Hierarchy......Page 148 5.3 The Multitouch Interface......Page 149 5.3.2 The UIEvent class......Page 150 5.3.3 The UIResponder class......Page 151 5.3.4 Handling a swipe......Page 155 5.3.5 More advanced gesture recognition......Page 160 5.4.1 Using the UIView class animation support......Page 164 5.4.3 Flip animation......Page 169 5.4.4 Transition animation......Page 170 5.5.1 Fundamentals......Page 172 5.5.2 The Summary View application......Page 174 Exercises......Page 183 6.1.1 UIControl attributes......Page 185 6.1.2 Target-action mechanism......Page 186 6.2 The Text Field......Page 189 6.2.1 Interacting with the keyboard......Page 191 6.2.2 The delegate......Page 194 6.2.3 Creating and working with a UITextField......Page 195 6.3 Sliders......Page 196 6.4 Switches......Page 197 6.5 Buttons......Page 198 6.6 Segmented Controls......Page 199 6.7 Page Controls......Page 202 6.8 Date Pickers......Page 203 Exercises......Page 205 7.1.1 The view controller......Page 207 7.1.2 The view......Page 209 7.1.3 The application delegate......Page 210 7.1.4 A simple MVC application......Page 211 7.2.1 A detailed example of a tab-bar application......Page 213 7.2.2 Some comments on tab-bar controllers......Page 218 7.3 Navigation Controllers......Page 222 7.3.1 A detailed example of a navigation controller......Page 223 7.3.2 Customization......Page 228 7.4 Modal View Controllers......Page 232 Exercises......Page 238 8.1 Picker View......Page 239 8.1.1 The delegate......Page 240 8.1.2 An example of picker view......Page 241 8.2 Progress View......Page 245 8.3 Scroll View......Page 249 8.4 Text View......Page 251 8.4.2 An example of text view......Page 252 8.5 Alert View......Page 255 8.6 Action Sheet......Page 257 8.7.1 A simple web view application......Page 259 8.7.2 Viewing local files......Page 264 8.7.3 Evaluating JavaScript......Page 268 8.7.4 The web view delegate......Page 275 8.8 Summary......Page 280 Exercises......Page 281 9.1 Overview......Page 283 9.2 The Simplest Table View Application......Page 284 9.3 A Table View with Both Images and Text......Page 289 9.4 A Table View with Section Headers and Footers......Page 291 9.5 A Table View with the Ability to Delete Rows......Page 293 9.6 A Table View with the Ability to Insert Rows......Page 299 9.7 Reordering Table Rows......Page 304 9.8 Presenting Hierarchical Information......Page 309 9.8.1 Detailed example......Page 312 9.9 Grouped Table Views......Page 319 9.10 Indexed Table Views......Page 322 9.11 Dynamic Table Views......Page 328 9.12 Whitening Text in Custom Cells......Page 331 9.13 Summary......Page 335 Exercises......Page 337 10.1 The Home Directory......Page 339 10.2 Enumerating a Directory......Page 340 10.3 Creating and Deleting a Directory......Page 342 10.4 Creating Files......Page 343 10.5 Retrieving and Changing Attributes......Page 347 10.5.1 Retrieving attributes......Page 348 10.5.2 Changing attributes......Page 349 10.6 Working with Resources and Low-Level File Access......Page 351 10.7 Summary......Page 354 Exercises......Page 355 11.1 Basic Database Operations......Page 357 11.1.2 Table operations......Page 359 11.2 Processing Row Results......Page 361 11.3.1 Preparation......Page 364 11.3.4 Putting it together......Page 365 11.4 User-Defined Functions......Page 367 11.5 Storing BLOBs......Page 371 11.6 Retrieving BLOBs......Page 375 Exercises......Page 377 12.1.1 XML......Page 379 12.1.2 RSS......Page 381 12.1.3 Configuring the XCode project......Page 384 12.2 Document Object Model (DOM)......Page 385 12.3 Simple API for XML (SAX)......Page 392 12.4 An RSS Reader Application......Page 401 12.5 Putting It Together......Page 404 Exercises......Page 405 13.1 The Core Location Framework......Page 407 13.1.1 The CLLocation class......Page 409 13.2 A Simple Location-Aware Application......Page 411 13.3 Google Maps API......Page 414 13.4 A Tracking Application with Maps......Page 420 13.5 Working with Zip Codes......Page 425 13.6.2 The MKCoordinateRegion structure......Page 428 13.6.3 The MKAnnotation protocol......Page 429 13.6.4 The MKAnnotationView class......Page 431 13.6.6 The MKPinAnnotationView class......Page 433 Exercises......Page 435 14.1.1 Basic accelerometer values......Page 437 14.1.2 Accelerometer example......Page 438 14.2.1 Playing short audio files......Page 442 14.2.2 Recording audio files......Page 444 14.2.3 Playing audio files......Page 445 14.2.4 Using the media picker controller......Page 446 14.2.5 Searching the iPod Library......Page 448 14.3 Playing Video......Page 451 14.4 Accessing Device Information......Page 452 14.5.1 Overall approach to taking and selecting pictures......Page 453 14.5.2 Detailed example of taking and selecting pictures......Page 454 14.6.1 Battery level......Page 456 14.6.2 Battery state......Page 457 14.6.4 Putting it together......Page 458 14.7.1 Enabling proximity monitoring......Page 459 14.7.3 Retrieving the proximity state......Page 460 Exercises......Page 461 15.1 String Localization......Page 463 15.2 Date Formatting......Page 469 15.3 Number Formatting......Page 472 15.4 Sorted List of Countries......Page 474 Exercises......Page 475 16.1 Text Field Alert View......Page 477 16.2 Table Alert View......Page 481 16.3 Progress Alert View......Page 486 Exercises......Page 491 17.1 Determining Network Connectivity......Page 493 17.1.1 Determining network connectivity via EDGE or GPRS......Page 494 17.1.3 Determining network connectivity via Wi-Fi......Page 495 17.2 Uploading Multimedia Content......Page 496 17.3 Computing MD5 Hash Value......Page 499 17.4.1 The Multithreaded Downloads application......Page 501 17.4.2 Asynchronous networking......Page 503 17.5.1 Configuring push notification on the server......Page 508 17.5.2 Configuring the client......Page 514 17.5.3 Coding the client......Page 517 17.5.4 Coding the server......Page 520 17.7 Large Downloads and Uploads......Page 521 17.8 Sending Email......Page 523 17.9 Summary......Page 526 Exercises......Page 527 18.1 Introduction......Page 529 18.3 Accessing Single-Value Properties......Page 530 18.3.1 Retrieving single-value properties......Page 531 18.4.1 Retrieving multivalue properties......Page 532 18.4.2 Setting multivalue properties......Page 534 18.5 Person and Group Records......Page 536 18.6 Address Book......Page 537 18.8 Person Photo Retriever Application......Page 539 18.9 Using the ABUnknownPersonViewController Class......Page 541 18.10 Using the ABPeoplePickerNavigationController Class......Page 542 18.11 Using the ABPersonViewController Class......Page 544 18.12 Using the ABNewPersonViewController Class......Page 546 18.13 Summary......Page 547 Exercises......Page 548 19.2 Key Players......Page 549 19.2.2 Managed object model......Page 550 19.2.5 Managed object......Page 551 19.2.6 The Core Data wrapper class......Page 552 19.3 Using the Modeling Tool......Page 555 19.4.1 Create......Page 560 19.4.3 Read and update......Page 561 19.5 Working with Relationships......Page 563 19.6.1 The UISearchDisplayController class......Page 564 19.6.2 Main pieces......Page 567 19.7 Summary......Page 571 Exercises......Page 572 20.1.1 Basic idea......Page 573 20.1.3 Registering an undo operation......Page 574 20.1.4 Hooking into the undo management mechanism......Page 575 20.2 Detailed Example......Page 576 20.2.3 Editing mode and the NSUndoManager instance......Page 577 20.2.4 Registering undo actions......Page 578 20.3 Wrapping Up......Page 579 Exercises......Page 580 21.1.2 Creating pasteboards......Page 581 21.2.1 Pasteboard items......Page 582 21.2.2 Manipulating pasteboard items......Page 583 21.3 The Editing Menu......Page 584 21.3.2 The UIMenuController class......Page 585 21.4 Putting It Together......Page 586 21.4.1 The image view......Page 587 21.4.2 The view controller......Page 588 21.5 Summary......Page 592 Exercises......Page 593 22.1 Setting Up the Project......Page 595 22.1.1 Adding support for libxml2......Page 596 22.1.2 Adding the TouchXML Objective-C wrapper......Page 597 22.2.1 The structure of the RSS feed......Page 598 22.2.3 Extracting parking availability......Page 599 22.2.4 Monitoring the feed and disseminating the updates......Page 601 22.3 Showing a Screen Shot of the Last Session......Page 603 22.4 The TableView Controller......Page 604 Exercises......Page 608 23.1.1 Peer discovery and connection establishment......Page 611 23.1.2 Creating the session......Page 612 23.1.3 Setting up a data-receive handler......Page 613 23.1.4 Sending data......Page 615 23.2.2 Receiving an image......Page 616 Exercises......Page 617 24.1.1 The application delegate class......Page 619 24.1.2 The CitiesViewController class......Page 620 24.1.3 The StatesViewController class......Page 622 24.1.4 Creating the UI......Page 624 24.2 The Cities App: Iteration 2......Page 628 24.2.1 Initializing the popover view controller with a navigation controller......Page 629 24.2.3 Wrapping it up......Page 631 24.3.1 An example of the split view controller......Page 632 24.3.2 Dissecting the split view controller......Page 634 24.5 Summary......Page 636 Exercises......Page 638 Appendix A Saving and Restoring App State......Page 639 Appendix B Invoking External Applications......Page 643 Appendix C App Store Distribution......Page 645 D.2 Creating Custom Templates......Page 647 D.3 Build-Based Configurations......Page 650 D.4 Using Frameworks......Page 653 E.1 Adding a Unit Test Target......Page 657 E.2 Adapting to Foundation......Page 658 E.3 The Model......Page 660 E.4 Writing Unit Tests for the Employee Class......Page 662 E.4.1 The setUp and tearDown methods......Page 663 E.4.3 Testing for nullity......Page 664 E.6 Running the Tests......Page 665 F.1.2 Creating the view controller class......Page 667 F.1.3 The application delegate class......Page 670 F.1.4 Building the UI......Page 671 F.2.1 Writing code......Page 685 F.2.2 Building the UI......Page 687 F.2.3 Putting it together......Page 693 References and Bibliography......Page 695 Index......Page 697
With Advanced iOS 4 Programming, developers have the expert guidance they need to create amazing applications for Apple's iPhone, iPad, and iPod touch.
Inside, veteran mobile developer Dr. Maher Ali begins with a foundation introduction to Objective C and Cocoa Touch programming, and then guides readers through building apps with Apple's iPhone SDK 4 – including coverage of the major categories of new APIs and building apps for the new Apple iPad.
This book concentrates on illustrating GUI concepts programmatically, allowing readers to fully appreciate the complete picture of iOS 4 development without relying on Interface Builder. In addition, Interface Builder is covered in several chapters.
Advanced iOS 4 Programming delves into more advanced topics going beyond the basics of iOS 4 development, providing comprehensive coverage that will help you get your apps to the App Store quicker.
Key features include:
- Objective-C programming language and runtime
- Interface Builder
- Building advanced mobile user interfaces
- Collections
- Cocoa Touch
- Core Animation and Quartz 2D
- Model-view-controller (MVC) designs
- Developing for the iPad
- Grand Central Dispatch
- Parsing XML documents using SAX, DOM, and TouchXML
- Working with the Map Kit API
- Remote and Local Push Notification
- Blocks (closures) in Objective-C
- Building advanced location-based applications
- Developing database applications using the SQLite engine
- GameKit framework
Getting started Objective-C and Cocoa Collections Anatomy of an iPhone application The view Controls View controllers Special-purpose views Table view File management Working with databases XML processing Location awareness Working with devices Internalization Custom user interface components Advanced networking Working with the address book database Core data Undo management Copy and paste Offline mode Peer-to-peer communication Developing for the iPad.