我想通过使用前置摄像头在iOS中捕获照片而无需任何用户交互。任何人都可以告诉我该怎么做吗?
我在takePicture
类中使用了UIImagePickerController
函数,但它没有用,因为委托方法(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)
信息永远不会被调用:
-(void)takePicture:(id)sender
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
//Use camera if device has one otherwise use photo library
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
}
else
{
[imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
}
[imagePicker setDelegate:self];
//Show image picker
[imagePicker takePicture];
}
有人能告诉我这样做的正确方法吗?
答案 0 :(得分:0)
您需要添加以下代码
//Getting image from front camera
imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
[self imagePicker animated:YES completion:nil];