Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

Share this Page URL
Help

Chapter 4. Using the Camera > Using the Camera - Pg. 52

Feedback: 0 Comments on this Section

Once you have determined that a camera is present you can inquire whether it supports video by making a call to determine the available media types the camera supports: NSArray *media = [UIImagePickerController availableMediaTypesForSourceType: UIImagePickerControllerSourceTypeCamera]; If the kUTTypeMovie media type is returned as part of the array, the camera will support video recording. Using the Camera The UIImagePickerViewController is an Apple-supplied interface for choosing images and movies, and on supported devices, taking new images or movies with the camera. As this class handles all of the required interaction with the user, it is very simple to use. All you need to do is tell it to start, and then dismiss it after the user selects an image or movie. Lets go ahead and build a simple application to illustrate how to use the image picker controller. Open Xcode and start a new project, select a View Based Application for the iPhone, naming it Media when requested. The first thing we want to do is set up our main view; this is going to consist of a single button that we'll push to bring up the Image Picker controller, and a UIImageView to display the image, or thumbnail of the video, that we're going to capture. So click on the MediaViewController.h interface file to open it in the editor and add a UIButton and an associated method to the interface file, flag these as an IBOutletand IBAction respectively. We also need to add a UIImageView to display that image returned by the image picker, which we also need to flag the UIImageView as an IBOutlet. Finally we need to add a UIImagePickerController, and flag the view controller as a UIImagePickerControllerDelegate and a UINavigationControllerDelegate. The added code is shown in bold: #import <UIKit/UIKit.h>