我正在写一个照片应用程序,我需要在带有双摄像头的iPhone相机视图中使用不同的叠加(考虑到变焦ui),是否有正确的方法来检查双摄像头是否存在?
我试图拿到设备并检查非双摄像头iPhone是否为零,因此它仍会重新调整设备:
let device = AVCaptureDevice.defaultDevice(withDeviceType: .builtInDualCamera, mediaType: AVMediaTypeVideo, position: .back)
任何人都知道如何检测双摄像头?
答案 0 :(得分:1)
就像苹果公司的例子一样:
if let device = AVCaptureDevice.defaultDevice(withDeviceType: .builtInDuoCamera,
mediaType: AVMediaTypeVideo,
position: .back) {
return device
} else if let device = AVCaptureDevice.defaultDevice(withDeviceType: .builtInWideAngleCamera,
mediaType: AVMediaTypeVideo,
position: .back) {
return device
} else {
return nil
}
答案 1 :(得分:1)
快捷键5 :
var currentDevice:AVCaptureDevice?
if let device = AVCaptureDevice.default(.builtInDualCamera, for: AVMediaType.video, position: .back) {
currentDevice = device
} else if let device = AVCaptureDevice.default(.builtInWideAngleCamera, for: AVMediaType.video, position: .back) {
currentDevice = device
} else {
print("Error: no camera available")
}