3

I am using code (which I used before XCode 4 in another project) and now if I switch my flashlight on, it flashes once before it stays on.

Like so: -*-**** where -=off & *=on

The code I am using:

AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if (toggleSwitch.on)
{
    NSLog( @"Light ON");

     AVCaptureSession *session = [[AVCaptureSession alloc] init];
     AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:nil];
     [session addInput:input];
     AVCaptureVideoDataOutput *output = [[AVCaptureVideoDataOutput alloc] init];
     [session addOutput:output];
     [session beginConfiguration];
     [device lockForConfiguration:nil];
     [device setTorchMode:AVCaptureTorchModeOn];
     [device unlockForConfiguration];
     [session commitConfiguration];
     [session startRunning];
    [self setAVSession:session];
    [output release];
    [session release];

}
else
{
    NSLog( @"Light OFF");

     [AVSession stopRunning];
     [AVSession release],AVSession = nil;

}

Switching it off works normal/fine.

Why would this happen? - How can I solve this problem?

Pangolin
  • 7,284
  • 8
  • 53
  • 67

1 Answers1

0

Checkout the answer on this Post - works much better with no flashing.

Turn on torch/flash on iPhone

Community
  • 1
  • 1
Ben
  • 1,537
  • 1
  • 10
  • 6