1

我想使用前置摄像头在没有任何用户交互的情况下在 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];
}

谁能告诉我正确的方法来做到这一点?

4

1 回答 1

0

您需要添加以下代码

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

[self imagePicker animated:YES completion:nil];
于 2013-05-20T08:54:27.790 回答