13.3. Taking Videos with the Camera


You want to allow your users to shoot a video using their iOS device, and you would like to be able to use that video from inside your application.


Use UIImagePickerController with the UIImagePickerControllerSourceTypeCamera source type and the kUTTypeMovie media type:

- (void)viewDidLoad{
  [super viewDidLoad];
  if ([self isCameraAvailable] &&
      [self doesCameraSupportTakingPhotos]){
    UIImagePickerController *controller = 
      [[UIImagePickerController alloc] init];
    controller.sourceType = UIImagePickerControllerSourceTypeCamera;
    NSString *requiredMediaType = (__bridge NSString *)kUTTypeMovie;
    controller.mediaTypes = [[NSArray alloc] 
                             initWithObjects:requiredMediaType, nil];    
    controller.allowsEditing = YES;
    controller.delegate = self;
    [self.navigationController presentModalViewController:controller
  } else {
    NSLog(@"Camera is not available.");


The isCameraAvailable and doesCameraSupportShootingVideos methods used in this sample code are implemented and discussed in Recipe 13.1.

We will implement the delegate methods of the image picker controller like so:

- (void)  imagePickerController:(UIImagePickerController *)picker 
  didFinishPickingMediaWithInfo:(NSDictionary *)info{
  NSLog(@"Picker returned successfully.");
  NSLog(@"%@", info);
  NSString     *mediaType = [info objectForKey:
  if ([mediaType isEqualToString:(__bridge NSString *)kUTTypeMovie]){
    NSURL *urlOfVideo =
    [info objectForKey:UIImagePickerControllerMediaURL ...

Get iOS 6 Programming Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.