如何用`AVFoundation检测相机存在? [英] How to detect camera existence with `AVFoundation`?
本文介绍了如何用`AVFoundation检测相机存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
现在iOS设备有0〜2个摄像头。如何检测它们?
Now iOS devices has 0~2 cameras. How to detect them?
推荐答案
您可以遍历视频设备...
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
}
}
当然,你也可以使用谓词更快一些,为了你的工作;)....(建议:使用filteredArrayUsingPredicate:方法在devicesWithMediaType:)
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:)
这篇关于如何用`AVFoundation检测相机存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文