2014-10-03 173 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屬性。

相關問題