Synopses & Reviews
This popular cookbook, thoroughly updated in response to reader requests and new developments in iOS 5, helps you solve the vexing, real-life issues youre likely to face when creating apps for the iPhone, iPad, or iPod Touch. This edition contains more than 100 new recipes, each providing a clear solution and sample code that you can use right away.
The focus of this book is to teach you how to write iOS apps, whether theyre as simple as a music player or as complex as an app that mixes animations, graphics, multimedia, database, and cloud storage. Youll learn about iCloud, Automatic Reference Counting, storyboarding, Interface Builder, creating ad-hoc and simulator builds, provision profiles, graphics, animations, Grand Central Dispatch, Operations and Operation Queues, threads, timers, audio and video and many other iOS 5 tools and techniques.
- Automatic Reference Counting to drastically cut down the time required to write your iOS apps
- iCloud to synchronize users data to the cloud
- Storyboarding to simplify creating your User Interface
- UI components, including picker views, data pickers, web views, popovers, activity indicators, progress views, sliders, alerts, switches, and many more
- Grand Central Dispatch to write blazingly fast iOS apps without having to worry about creating threads
- The all-new asynchronous and synchronous network APIs
- Using block-based animations and integrating graphical assets into your apps
With the recipes in this updated cookbook, you'll go beyond theory to solve the vexing, real-life issues you're likely to face when creating apps for the iPhone, iPad, or iPod Touch. Each recipe provides a clear solution and sample code that you can use right away. You'll find solutions for working with development frameworks in iOS SDK 5 and technologies such as Cocoa, Objective-C, Xcode, and Interface Builder. Whether you have a little or a lot of experience with iOS development, you'll find the help you need for every phase of the process, from initial idea to completed project.
- Work with Objective-C classes, objects, properties, delegates, and memory management
- Construct a user interface with gesture recognizers
- Develop location-aware applications with the Map Kit and Core Location APIs
- Build apps that play audio and video, manage calendars and events, access contacts and groups, or tap into the Photo Library
- Use the Core Motion framework to access the accelerometer and gyroscope
- Maintain persistent storage for iOS apps with the Core Data framework
- Create multitasking-aware apps that let users leave and return without losing their place
Now you can overcome the vexing, real-life issues you confront when creating apps for the iPhone, iPad, or iPod Touch. By making use of more than 100 new recipes in this updated cookbook, youll quickly learn the steps necessary for writing complete iOS apps, whether theyre as simple as a music player or feature a complex mix of animations, graphics, multimedia, a database, and iCloud storage.
If youre comfortable with iOS SDK, this cookbook will teach you how to use hundreds of iOS techniques. Each recipe provides a clear solution with sample code that you can use right away.
- Use different approaches to construct a user interface
- Develop location-aware apps
- Get working examples for implementing gesture recognizers
- Play audio and video files and access the iPod library
- Retrieve contacts and groups from the Address Book
- Determine camera availability and access the Photo Library
- Create multitasking-aware apps
- Maintain persistent storage in your apps
- Use Event Kit to manage calendars and events
- Learn capabilities of the Core Graphics framework
- Access the accelerometer and gyroscope
- Take advantage of the iCloud service
About the Author
Vandad Nahavandipoor is currently an iOS programmer for a leading digital media distributor in London, United Kingdom. He has led an international team of more than 30 iOS developers in his previous job. Some of the projects he has lead include the NatWest and the RBS iOS apps running on millions of iPhones and iPads in the UK. Vandad received his B.Sc and M.Sc in Information Technology for E-Commerce from the University of Sussex in England.
Vandad's programming experience started when he first learned Basic on his father's Commodore 64. He then took this experience and applied it on his uncle's Intel 186 computer, running Basic on DOS. At this point, he found programming for personal computers exciting indeed and moved on to learn Object Pascal. This allowed him to learn Borland Delphi quite easily. He wrote a short 400 pages book on Borland Delphi and dedicated the book to Borland. From then, he picked up x86 Assembly programming and wrote a hobby 32-bit operating system named Vandior. It wasn't until late 2007 when iOS programming became his main focus.
Aside from programming, Vandad is a road cyclist, enjoying friendly competition in cyclosportive events in England and traveling long distance on his bicycle to other European countries every now and then. He also enjoys tinkering with his piano and playing electric guitar. Some of his electric guitar performances are available on YouTube.
Table of Contents
Dedication; Preface; Audience; Organization of This Book; Additional Resources; Conventions Used in This Book; Using Code Examples; We'd Like to Hear from You; Safari® Books Online; Acknowledgments; Chapter 1: The Basics; 1.1 Introduction; 1.2 Creating a Simple iOS App in Xcode; 1.3 Understanding Interface Builder; 1.4 Compiling iOS Apps; 1.5 Running iOS Apps on the Simulator; 1.6 Running iOS Apps on iOS Devices; 1.7 Packaging iOS Apps for Distribution; 1.8 Declaring Variables in Objective-C; 1.9 Allocating and Making Use of Strings; 1.10 Comparing Values in Objective-C with an If Statement; 1.11 Implementing Loops with For Statements; 1.12 Implementing While Loops; 1.13 Creating Custom Classes; 1.14 Defining Functionality for Classes; 1.15 Defining Two or More Methods with the Same Name; 1.16 Allocating and Initializing Objects; 1.17 Adding Properties to Classes; 1.18 Moving From Manual Reference Counting to Automatic Reference Counting; 1.19 Typecasting with Automatic Reference Counting; 1.20 Delegating Tasks with Protocols; 1.21 Determining Whether Instance or Class Methods Are Available; 1.22 Determining Whether a Class Is Available at Runtime; 1.23 Allocating and Making Use of Numbers; 1.24 Allocating and Making Use of Arrays; 1.25 Allocating and Making Use of Dictionaries; 1.26 Allocating and Making Use of Sets; 1.27 Creating Bundles; 1.28 Loading Data From the Main Bundle; 1.29 Loading Data From Other Bundles; 1.30 Sending Notifications with NSNotificationCenter; 1.31 Listening for Notifications Sent From NSNotificationCenter; Chapter 2: Implementing Controllers and Views; 2.1 Introduction; 2.2 Displaying Alerts with UIAlertView; 2.3 Creating and Using Switches with UISwitch; 2.4 Picking Values with UIPickerView; 2.5 Picking the Date and Time with UIDatePicker; 2.6 Implementing Range Pickers with UISlider; 2.7 Grouping Compact Options with UISegmentedControl; 2.8 Presenting and Managing Views with UIViewController; 2.9 Implementing Navigation with UINavigationController; 2.10 Manipulating a Navigation Controller's Array of View Controllers; 2.11 Displaying an Image on a Navigation Bar; 2.12 Adding Buttons to Navigation Bars Using UIBarButtonItem; 2.13 Presenting Multiple View Controllers with UITabBarController; 2.14 Displaying Static Text with UILabel; 2.15 Accepting User Text Input with UITextField; 2.16 Displaying Long Lines of Text with UITextView; 2.17 Adding Buttons to the User Interface with UIButton; 2.18 Displaying Images with UIImageView; 2.19 Creating Scrollable Content with UIScrollView; 2.20 Loading Web Pages with UIWebView; 2.21 Presenting Master-Detail Views with UISplitViewController; 2.22 Enabling Paging with UIPageViewController; 2.23 Displaying Popovers with UIPopoverController; 2.24 Displaying Progress with UIProgressView; 2.25 Listening and Reacting to Keyboard Notifications; Chapter 3: Constructing and Using Table Views; 3.1 Introduction; 3.2 Instantiating a Table View; 3.3 Assigning a Delegate to a Table View; 3.4 Populating a Table View with Data; 3.5 Receiving and Handling Table View Events; 3.6 Using Different Types of Accessories in a Table View Cell; 3.7 Creating Custom Table View Cell Accessories; 3.8 Displaying Hierarchical Data in Table Views; 3.9 Enabling Swipe Deletion of Table View Cells; 3.10 Constructing Headers and Footers in Table Views; 3.11 Displaying Context Menus on Table Views Cells; 3.12 Moving Cells and Sections in Table Views; 3.13 Deleting Cells and Sections From Table Views; Chapter 4: Storyboards; 4.1 Introduction; 4.2 Creating a Project with Storyboards; 4.3 Adding a Navigation Controller to a Storyboard; 4.4 Passing Data From One Screen to Another; 4.5 Adding a Storyboard to an Existing Project; Chapter 5: Concurrency; 5.1 Introduction; 5.2 Constructing Block Objects; 5.3 Accessing Variables in Block Objects; 5.4 Invoking Block Objects; 5.5 Dispatching Tasks to Grand Central Dispatch; 5.6 Performing UI-Related Tasks with GCD; 5.7 Performing Non-UI Related Tasks Synchronously with GCD; 5.8 Performing Non-UI Related Tasks Asynchronously with GCD; 5.9 Performing Tasks After a Delay with GCD; 5.10 Performing a Task Only Once with GCD; 5.11 Grouping Tasks Together with GCD; 5.12 Constructing Your Own Dispatch Queues with GCD; 5.13 Running Tasks Synchronously with Operations; 5.14 Running Tasks Asynchronously with Operations; 5.15 Creating Dependency Between Operations; 5.16 Creating Timers; 5.17 Creating Concurrency with Threads; 5.18 Invoking Background Methods; 5.19 Exiting Threads and Timers; Chapter 6: Core Location and Maps; 6.1 Introduction; 6.2 Creating a Map View; 6.3 Handling the Events of a Map View; 6.4 Pinpointing the Location of a Device; 6.5 Displaying Pins on a Map View; 6.6 Displaying Pins with Different Colors on a Map View; 6.7 Displaying Custom Pins on a Map View; 6.8 Converting Meaningful Addresses to Longitude and Latitude; 6.9 Converting Longitude and Latitude to a Meaningful Address; Chapter 7: Implementing Gesture Recognizers; 7.1 Introduction; 7.2 Detecting Swipe Gestures; 7.3 Detecting Rotation Gestures; 7.4 Detecting Panning and Dragging Gestures; 7.5 Detecting Long Press Gestures; 7.6 Detecting Tap Gestures; 7.7 Detecting Pinch Gestures; Chapter 8: Networking, JSON, XML, and Twitter; 8.1 Introduction; 8.2 Downloading Asynchronously with NSURLConnection; 8.3 Handling Timeouts in Asynchronous Connections; 8.4 Downloading Synchronously with NSURLConnection; 8.5 Modifying a URL Request with NSMutableURLRequest; 8.6 Sending HTTP GET Requests with NSURLConnection; 8.7 Sending HTTP POST Requests with NSURLConnection; 8.8 Sending HTTP DELETE Requests with NSURLConnection; 8.9 Sending HTTP PUT Requests with NSURLConnection; 8.10 Serializing Arrays and Dictionaries into JSON; 8.11 Deserializing JSON into Arrays and Dictionaries; 8.12 Integrating Twitter Functionality into Your Apps; 8.13 Parsing XML with NSXMLParser; Chapter 9: Audio and Video; 9.1 Introduction; 9.2 Playing Audio Files; 9.3 Handling Interruptions While Playing Audio; 9.4 Recording Audio; 9.5 Handling Interruptions While Recording Audio; 9.6 Playing Audio Over Other Active Sounds; 9.7 Playing Video Files; 9.8 Capturing Thumbnails From a Video File; 9.9 Accessing the Music Library; Chapter 10: Address Book; 10.1 Introduction; 10.2 Retrieving a Reference to an Address Book; 10.3 Retrieving All the People in the Address Book; 10.4 Retrieving Properties of Address Book Entries; 10.5 Inserting a Person Entry into the Address Book; 10.6 Inserting a Group Entry into the Address Book; 10.7 Adding Persons to Groups; 10.8 Searching the Address Book; 10.9 Retrieving and Setting a Person's Address Book Image; Chapter 11: Camera and the Photo Library; 11.1 Introduction; 11.2 Detecting and Probing the Camera; 11.3 Taking Photos with the Camera; 11.4 Taking Videos with the Camera; 11.5 Storing Photos in the Photo Library; 11.6 Storing Videos in the Photo Library; 11.7 Retrieving Photos and Videos From the Photo Library; 11.8 Retrieving Assets From the Assets Library; 11.9 Editing Videos on an iOS Device; Chapter 12: Multitasking; 12.1 Introduction; 12.2 Detecting the Availability of Multitasking; 12.3 Completing a Long-Running Task in the Background; 12.4 Receiving Local Notifications in the Background; 12.5 Playing Audio in the Background; 12.6 Handling Location Changes in the Background; 12.7 Saving and Loading the State of Multitasking iOS Apps; 12.8 Handling Network Connections in the Background; 12.9 Handling Notifications Delivered to a Waking App; 12.10 Responding to Changes in App Settings; 12.11 Opting Out of Multitasking; Chapter 13: Core Data; 13.1 Introduction; 13.2 Creating a Core Data Model with Xcode; 13.3 Generating Class Files for Core Data Entities; 13.4 Creating and Saving Data Using Core Data; 13.5 Reading Data From Core Data; 13.6 Deleting Data From Core Data; 13.7 Sorting Data in Core Data; 13.8 Boosting Data Access in Table Views; 13.9 Implementing Relationships in Core Data; Chapter 14: Dates, Calendars, and Events; 14.1 Introduction; 14.2 Retrieving the List of Calendars; 14.3 Adding Events to Calendars; 14.4 Accessing the Contents of Calendars; 14.5 Removing Events From Calendars; 14.6 Adding Recurring Events to Calendars; 14.7 Retrieving the Attendees of an Event; 14.8 Adding Alarms to Calendars; 14.9 Handling Event Changed Notifications; 14.10 Presenting Event View Controllers; 14.11 Presenting Event Edit View Controllers; Chapter 15: Graphics and Animations; 15.1 Introduction; 15.2 Enumerating and Loading Fonts; 15.3 Drawing Text; 15.4 Constructing, Setting, and Using Colors; 15.5 Drawing Images; 15.6 Drawing Lines; 15.7 Constructing Paths; 15.8 Drawing Rectangles; 15.9 Adding Shadows to Shapes; 15.10 Drawing Gradients; 15.11 Displacing Shapes Drawn on Graphic Contexts; 15.12 Scaling Shapes Drawn on Graphic Contexts; 15.13 Rotating Shapes Drawn on Graphic Contexts; 15.14 Animating and Moving Views; 15.15 Animating and Scaling Views; 15.16 Animating and Rotating Views; Chapter 16: Core Motion; 16.1 Introduction; 16.2 Detecting the Availability of an Accelerometer; 16.3 Detecting the Availability of a Gyroscope; 16.4 Retrieving Accelerometer Data; 16.5 Detecting Shakes on an iOS Device; 16.6 Retrieving Gyroscope Data; Chapter 17: iCloud; 17.1 Introduction; 17.2 Setting Up Your App for iCloud; 17.3 Storing and Synchronizing Dictionaries in iCloud; 17.4 Creating and Managing Folders for Apps in iCloud; 17.5 Searching for Files and Folders in iCloud; 17.6 Storing User Documents in iCloud; 17.7 Managing the State of Documents in iCloud; 17.8 Handling Conflicts in iCloud Documents; Colophon;