我知道,打开闪光灯并将其保持在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)。

谢谢

最佳答案

在您的代码中设置了lockforConfiguration,您在其中声明AVCaptureDevice是一个属性。

[videoCaptureDevice lockForConfiguration:nil];

关于ios - 在iPhone上打开手电筒/闪光灯,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3190034/

10-10 08:18