2017-07-14 59 views
0

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

+0

是的,它可以在原生应用程序中打开默认相机 –

+0

这怎么可能?你能给我任何解决方案吗? – Sarmistha

回答

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。你不能直接使用它们。

+0

感谢您的回答。 – Sarmistha

+0

视频截图@Nirmalsinh –

+0

结帐我更新的答案。 – Nirmalsinh