在没有用户交互的情况下捕获图像

时间:2013-05-20 08:43:39

标签: ios objective-c xcode uiimagepickercontroller

我想通过使用前置摄像头在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];
}

有人能告诉我这样做的正确方法吗?

1 个答案:

答案 0 :(得分:0)

您需要添加以下代码

//Getting image from front camera
imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceFront;

[self imagePicker animated:YES completion:nil];