如何打开iphone 4上的LED灯?

时间:2010-07-01 04:14:08

标签: iphone camera led iphone-4

  

可能重复:
  Turn on torch/flash on iPhone 4

我只想打开LED灯。有没有一种简单的方法可以做到这一点,或者我是否需要设置手机拍摄视频,模拟视频开启,但不保存视频?那样的东西?感谢。

1 个答案:

答案 0 :(得分:2)

试试这个,它对我来说很好。

#import <AVFoundation/AVFoundation.h>


- (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];
        torchIsOn = YES;
    } else {
        [device setTorchMode:AVCaptureTorchModeOff];
        [device setFlashMode:AVCaptureFlashModeOff];
        torchIsOn = NO;            
    }
    [device unlockForConfiguration];
    }
  }
}