在 iPhone 上打开手电筒/闪光灯 [英] Turn on torch/flash on iPhone
本文介绍了在 iPhone 上打开手电筒/闪光灯的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道在 iPhone 4 上开启闪光灯并保持开启的唯一方法是打开摄像机.虽然我不太确定代码.这是我正在尝试的:
I know that the only way to turn on the flash and keep it on on iPhone 4 is by turning the video camera on. I'm not too sure of the code though. Here is what I am trying:
-(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).
Does anybody know if this would work or am I missing anything? (I don't have an iPhone 4 yet to test on -just trying out some of the new API's).
谢谢
推荐答案
lockforConfiguration
在您的代码中设置,您可以在其中声明 AVCaptureDevice
是一个属性.>
the lockforConfiguration
is set in your code, where you declare your AVCaptureDevice
is a property.
[videoCaptureDevice lockForConfiguration:nil];
这篇关于在 iPhone 上打开手电筒/闪光灯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文