Spire
Spire

Reputation: 1065

control the camera flash iPhone

I was wondering if it is possible to set up an app that will turn on and off the flash of the camera in sequences like a Morse code or an SOS signal or something similar. I have done a little research but i didnt find anything conclusive.

Any ideas? :)

Upvotes: 0

Views: 839

Answers (1)

yuji
yuji

Reputation: 16725

Here's how to turn on the flashlight:

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];

And to turn it off again:

[session stopRunning];

You'll need to turn the flashlight on and off with the timings you want using something like NSTimer.

Upvotes: 1

Related Questions