Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save schifano/9c7a599547b2df7e9a1e to your computer and use it in GitHub Desktop.
Save schifano/9c7a599547b2df7e9a1e to your computer and use it in GitHub Desktop.
An incomplete example.
AVCaptureSession *session = [[AVCaptureSession alloc] init];
AVCaptureDevice *captureDevice = [[AVCaptureDevice alloc] init];
// Add input/output devices
// Check what media type is supported by the device
NSArray *devices = [AVCaptureDevice devices];
for (AVCaptureDevice *device in devices) {
NSLog(@"Device name: %@", [device localizedName]);
if ([device hasMediaType:AVMediaTypeVideo]) {
if ([device position] == AVCaptureDevicePositionFront){
NSLog(@"Device position: front");
captureDevice = device;
// We have a front-facing video device
if (captureDevice != NULL) {
NSLog(@"Capture device found");
// Add a device to the AVCaptureSession, AVCaptureDeviceInput
NSError *error;
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
if (!input) {
// Handle error
}
}
} else {
NSLog(@"Device position: back - Don't want");
}
}
}
// Start data flow - eventually want to also stopRunning
[session startRunning];
@nazmul202101
Copy link

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment