Search code examples
ioszbar-sdk

How to set camera flash light level in zbar sdk


I am using zbar sdk in my ios app. I want to dim the camera flash light. In ios documentation I have found AVCaptureDevice

- (BOOL)setTorchModeOnWithLevel:(float)torchLevel error:(NSError **)outError

In AVCaptureDevice class setTorchModeOnWithLevel function sets the light level between 0-1. In zbar sdk I have found this object in readerview class I am using following code

    ZBarReaderViewController *mReader =  [[ZBarReaderViewController alloc] init];
    mReader.showsZBarControls = NO;
    mReader.showsHelpOnFail = NO;
    mReader.cameraFlashMode = UIImagePickerControllerCameraFlashModeOff;

    mReader.readerDelegate = self;
    //    reader.cameraDevice = UIImagePickerControllerCameraDeviceFront;
    mReader.supportedOrientationsMask = ZBarOrientationMaskAll;
    CGRect cropRect = CGRectMake(0, 0, cameraView.frame.size.width , cameraView.frame.size.height);

    mReader.view.frame = cropRect;

    mReader.cameraOverlayView = [self setOverlayPickerView];
    AVCaptureDevice *mDevice = mReader.readerView.device; //mReader.readerView.device returns object of AVCaptureDevice

When I try to access AVCaptureDevice functions it show nothing in suggestion and when I write it manually then it give error.

[mDevice setTorchModeOnWithLevel:0.5 error:error];

How I can use AVCaptureDevice object so that I can set the dim level of flash light??


Solution

  • I was calling following function which give error

    [mDevice setTorchModeOnWithLevel:0.5 error:error];
    

    The reason of error was that I have not included AVFoundation library in build setting. After including my error resolves @rakeshNS we can dim the zbar sdk light by using

    AVCaptureDevice *mDevice = mReader.readerView.device;
    [mDevice setTorchModeOnWithLevel:0.5 error:nil];
    

    Thanks to everybody