关于默认相机

时间:2017-07-14 12:03:07

标签: objective-c

是否可以使用目标c从我的应用中打开默认的iPhone Camara? 此外,当从本机应用程序打开时,是否可以捕获从默认相机中选择的图像或视频?

1 个答案:

答案 0 :(得分:0)

您无法从应用中打开默认相机应用程序。要将相机放入您的应用程序,您需要使用UIImagePickerController。它将完成您想要完成的大部分任务。

以下是集成它的代码。

UIImagePickerController * imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.delegate = self;
[self presentModalViewController:imagePicker animated:YES];


- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    [self dismissModalViewControllerAnimated:YES];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    UIImage * image = [info objectForKey:UIImagePickerControllerEditedImage];

    // You have the image. You can use this to present the image in the next view like you require in `#3`.

    [self dismissModalViewControllerAnimated:YES];
}

用于捕捉视频:

      UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.delegate = self;
        picker.allowsEditing = YES;
        picker.sourceType = UIImagePickerControllerSourceTypeCamera;
        picker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];

        [self presentViewController:picker animated:YES completion:NULL];
    }

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
     self.videoURL = info[UIImagePickerControllerMediaURL];
    [picker dismissViewControllerAnimated:YES completion:NULL];

    self.videoController = [[MPMoviePlayerController alloc] init];

    [self.videoController setContentURL:self.videoURL];
    [self.videoController.view setFrame:CGRectMake (0, 0, 320, 460)];
    [self.view addSubview:self.videoController.view];

    [self.videoController play];

}

阅读this apple documentation。有6种标准方案:邮件,电话,文本,地图,YouTube,iTunes。你不能直接使用它们。