O'Reilly logo

Beginning iOS 5 Application Development by Wei-Meng Lee

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

ACCESSING THE CAMERA AND THE PHOTO LIBRARY

The iPhone 4 (and 4S) (as well as the iPad 2) has a camera (in fact two - one front facing and one rear facing) that enables users to both take pictures and record videos. These pictures and videos are saved in the Photos application. As a developer, you have two options to manipulate the camera and to access the pictures and videos stored in the Photos application:

  • You can invoke the camera to take pictures or record a video.
  • You can invoke the Photos application to allow users to select a picture or video from the photo albums. You can then use the picture or video selected in your application.

Accessing the Photo Library

Every iOS device includes the Photos application, in which pictures are stored. Using the iOS SDK, you can use the UIImagePickerController class to programmatically display a UI that enables users to select pictures from the Photos application. The following Try It Out demonstrates how you can do that in your application.

TRY IT OUT: Accessing the Photos in the Photo Library

image

  1. Using Xcode, create a Single View Application (iPhone) project and name it PhotoLibrary. You will also use the project name as the Class Prefix and ensure that you have the Use Automatic Reference Counting option unchecked.
  2. Select the PhotoLibraryViewController.xib file to edit it in Interface Builder.
  3. Populate the View window with the following ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required