@IBOutlet weak var viewCam: UIView!
let captureSession = AVCaptureSession()
var captureDevice : AVCaptureDevice?
var previewLayer : AVCaptureVideoPreviewLayer?
captureSession.sessionPreset = AVCaptureSession.Preset.low
// Get all audio and video devices on this machine
let devices = AVCaptureDevice.devices()
// Find the FaceTime HD camera object
for device in devices {
print(device)
if ((device as AnyObject).hasMediaType(AVMediaType.video)) {
print(device)
captureDevice = device as? AVCaptureDevice
}
}
if captureDevice != nil {
do {
try captureSession.addInput(AVCaptureDeviceInput(device: captureDevice!))
previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
previewLayer?.frame = (self.viewCam.frame)
// Add previewLayer into custom view
self.viewCam.layer.addSublayer(previewLayer!)
// Start camera
} catch {
print(AVCaptureSessionErrorKey.description)
}
}
I am using this code in Mac-catalist (iOS) and it works fine for iPhone iPad but its returning captureDevice nil on Mac.
But when I used same code in Mac native build it worked fine. I am not sure how to achieve this in Mac-catalist.
Please answer below or make comments, thanks in advance.