在iPhone上打开手电筒/闪光灯

约翰

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

谢谢

古斯塔沃·巴里恩托斯(Gustavo Barrientos)

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

[videoCaptureDevice lockForConfiguration:nil];

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章