2017-07-14 84 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