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
- 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.
- Select the PhotoLibraryViewController.xib file to edit it in Interface Builder.
- Populate the View window with the following ...
Get Beginning iOS 5 Application Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.