【发布时间】:2011-03-12 12:39:41
【问题描述】:
我知道在 iPhone 4 上打开闪光灯并使其保持打开状态的唯一方法是打开摄像机。不过,我不太确定代码。这是我正在尝试的:
-(IBAction)turnTorchOn {
AVCaptureSession *captureSession = [[AVCaptureSession alloc] init];
AVCaptureDevice *videoCaptureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
NSError *error = nil;
AVCaptureDeviceInput *videoInput = [AVCaptureDeviceInput deviceInputWithDevice:videoCaptureDevice error:&error];
if (videoInput) {
[captureSession addInput:videoInput];
AVCaptureVideoDataOutput* videoOutput = [[AVCaptureVideoDataOutput alloc] init];
[videoOutput setSampleBufferDelegate:self queue:dispatch_get_current_queue()];
[captureSession addOutput:videoOutput];
[captureSession startRunning];
videoCaptureDevice.torchMode = AVCaptureTorchModeOn;
}
}
有人知道这是否可行还是我遗漏了什么? (我还没有要测试的 iPhone 4 - 只是尝试一些新的 API)。
谢谢
【问题讨论】:
-
我编写了一个适用于 Cordova 2.2.0 的 Torch 插件。你可以在这里找到它:github.com/tomschreck/iOS-Torch-Plugin
标签: ios iphone avcapturesession avcapturedevice