2014-10-03 608 views
3

我需要使用前置摄像头并在iPhone中打开背光LED。 我该怎么做? 我可以使用此代码打开前置摄像头:在iPhone上同时打开闪光灯和前置摄像头

- (void) turnCameraOn { 
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { 

    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; 
    imagePicker.delegate = self; 
    imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; 
    imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceFront; 
    imagePicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto; 
    imagePicker.showsCameraControls = YES; 

    [self presentViewController:imagePicker animated:YES completion:nil]; 

} else { 

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Camera unavaliable" 
                message:@"Unable to find camera on your device." 
                delegate:nil 
              cancelButtonTitle:@"OK" 
              otherButtonTitles:nil, nil]; 
    [alert show]; 
    alert = nil; 
} 
} 

,我可以打开LED与此代码

- (void) turnTorchOn: (bool) on { 
Class captureDeviceClass = NSClassFromString(@"AVCaptureDevice"); 
if (captureDeviceClass != nil) { 
    AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; 
    if ([device hasTorch] && [device hasFlash]){ 

     [device lockForConfiguration:nil]; 

     if (on) { 
      [device setTorchMode:AVCaptureTorchModeOn]; 
      [device setFlashMode:AVCaptureFlashModeOn]; 
     } else { 
      [device setTorchMode:AVCaptureTorchModeOff]; 
      [device setFlashMode:AVCaptureFlashModeOff]; 
     } 
     [device unlockForConfiguration]; 
    } 
} 
} 

但是当我打开APP和前置摄像头出现在LED熄灭。 我需要同时工作。

谢谢

+0

到目前为止这个运气还好吗? – 2014-10-11 14:32:07

+0

没有:(看起来像苹果可以做到这一点,因为如果你意识到苹果手电筒不像所有其他手电筒应用程序一样访问摄像头 – rendellhb 2014-10-14 21:04:29

+0

@rendellhb:我想在android.do中使用相同的功能。你知道这可能吗? – Basher51 2014-11-08 15:45:19

回答

0

这是不允许在iOS上使用当前的一组API。 你可以通过苹果自己的相机应用程序了解这一点。

即使它们在切换为使用前置摄像头时也会关闭割炬,并且不会在该模式下显示割炬开关。

0

documentation检查出isFlashAvailableForCameraDevice属性的UIImagePickerController来检查闪存是否允许与UIImagePickerControllerCameraDeviceFront属性。

相关问题