简体   繁体   English

如何检查iPhone是否有双摄像头?

[英]How to check if iPhone has dual camera?

I'm writing a photo app and I need different overlays in the camera view for iPhones with dual camera (to account for the zoom ui), is there a proper way to check if a dual camera exists?我正在编写一个照片应用程序,我需要在带有双摄像头的 iPhone 的摄像头视图中使用不同的叠加层(考虑到变焦 ui),是否有正确的方法来检查双摄像头是否存在?

I tried to get the device and check if it was nil for the non dual camera iPhones, tho it still retunes a device:我尝试获取设备并检查它对于非双摄像头 iPhone 是否为零,但它仍然会重新调整设备:

let device = AVCaptureDevice.defaultDevice(withDeviceType: .builtInDualCamera, mediaType: AVMediaTypeVideo, position: .back)

Dose anyone know how to detect the dual camera?有谁知道如何检测双摄像头?

Just as the apple's example:就像苹果的例子:

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
    }

Swift 5 :斯威夫特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")
            }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM