如何用'AVFoundation`检测相机的存在?

时间:2011-03-18 09:24:45

标签: ios camera detection

现在iOS设备有0~2台摄像头。如何检测它们?

1 个答案:

答案 0 :(得分:18)

您遍历视频设备......

NSArray *videoDevices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
AVCaptureDevice *captureDevice = nil;

for (AVCaptureDevice *device in videoDevices) {
    if (device.position == AVCaptureDevicePositionFront) {
        //FRONT-FACING CAMERA EXISTS
    }
}

当然你也可以用谓词更快地做到这一点,但是我会留给你解决问题;)....(提示:在devicesWithMediaType上使用filteredArrayUsingPredicate:方法:)