O'Reilly logo

iPhone and iPad App 24-Hour Trainer by Gene Backlin, Abhishek Mishra

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

Chapter 36

Using the Camera and Photo Library

All iOS devices, with the exception of the first-generation iPad, have at least one camera. When a user takes a picture with the camera, the image is stored in the device’s photo library. This lesson shows you how to allow the user to pick an image from the photo library or take a new picture with the camera and use it in your application.

The UIKit framework contains a class called UIImagePickerController designed specifically to allow you to access the camera and photo library from your applications. This class presents its own user interface (Figure 36-1) that allows a user to browse through the photo library or control the camera. All you have to do is present this view controller in your application and provide a delegate method whose methods are called when the user has finished selecting an image.

The image picker controller can also be used to record videos and access these recorded videos within your application. Video recording and playback is not covered in this book.

Creating an instance of the UIImagePickerController is a simple matter of sending it an alloc and init message:

UIImagePickerController* imagePicker = [[UIImagePickerController alloc] 
                                        init];

The UIImagePickerController class can be used to access the contents of either the photo library, saved photos album, or the camera. You can specify the source ...

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