How to detect camera existence using "AVFoundation"?

IOS devices now have 0 ~ 2 cameras. How to find them?

+3
source share
1 answer

You are repeating video devices ...

NSArray *videoDevices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]; AVCaptureDevice *captureDevice = nil; for (AVCaptureDevice *device in videoDevices) { if (device.position == AVCaptureDevicePositionFront) { //FRONT-FACING CAMERA EXISTS } } 

Of course, you could do it a little faster with the predicate, but I will leave it for you to work out;) .... (TIP: use the filterArrayUsingPredicate: method on devicesWithMediaType :)

+18
source

All Articles