It looks like you're new here. If you want to get involved, click one of these buttons!
- (BOOL) toggleCamera
{
BOOL success = NO;
if ([self cameraCount] > 1) {
NSError *error;
AVCaptureDeviceInput *captureInput;
AVCaptureDevicePosition position = [[videoInput device] position];
if (position == AVCaptureDevicePositionBack)
captureInput = [[AVCaptureDeviceInput alloc] initWithDevice:[self frontFacingCamera] error:&error];
else if (position == AVCaptureDevicePositionFront)
captureInput = [[AVCaptureDeviceInput alloc] initWithDevice:[self backFacingCamera] error:&error];
else
goto bail;
AVCaptureSession *captureSession = [[AVCaptureSession alloc] init];
if (captureInput != nil) {
[captureSession addInput:captureInput];
AVCaptureVideoDataOutput* captureOutput = [[AVCaptureVideoDataOutput alloc] init];
[captureOutput setSampleBufferDelegate:self queue:dispatch_get_current_queue()];
[captureSession addOutput:captureOutput];
[captureSession startRunning];
}
}
bail:
return success;
}