Search code examples
iosobjective-ccocoa-touchplaybackavcapturedevice

How to get the iOS devices camera name?


Does IOS capture devices and playback devices have any name or path? Usually we can able to get path for connected camera and its name in windows, I guess in Mac also we can do that. Anyone have idea about how to get name and path of capture and playback devices on IOS?

  // RETURNS HOW MANY AUDIO CAPTURE DEVICES ARE THERE... 
  for eg: [[AVCaptureDevice devicesWithMediaType:AVMediaTypeAudio] count];

Solution

  • NSArray *devices = [AVCaptureDevice devices];
    AVCaptureDevice *frontCamera;
    AVCaptureDevice *backCamera;
    
    for (AVCaptureDevice *device in devices) {
    
        NSLog(@"Device name: %@", [device localizedName]);
    
        if ([device hasMediaType:AVMediaTypeVideo]) {
    
            if ([device position] == AVCaptureDevicePositionBack) {
                NSLog(@"Device position : back");
                backCamera = device;
            }
            else {
                NSLog(@"Device position : front");
                frontCamera = device;
            }
        }
    }