How to detect camera existence with `AVFoundation`?

本秂侑毒 提交于 2019-12-07 12:24:25

问题


Now iOS devices has 0~2 cameras. How to detect them?


回答1:


You iterate through the 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 also do this a bit quicker with a predicate, but i'll leave that for you to work out ;).... (HINT: use the filteredArrayUsingPredicate: method on the devicesWithMediaType:)



来源:https://stackoverflow.com/questions/5350079/how-to-detect-camera-existence-with-avfoundation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!