'AVCapturePhotoSettings' 类型的值没有成员 'availablePreviewPhotoPixelFormatTypes

Value of type 'AVCapturePhotoSettings' has no member 'availablePreviewPhotoPixelFormatTypes

@objc func launchCoreML() {
    let settings = AVCapturePhotoSettings()
    let previewPixelType = settings.availablePreviewPhotoPixelFormatTypes.first
    let previewFormat = [
        kCVPixelBufferPixelFormatTypeKey as String: previewPixelType, 
        kCVPixelBufferWidthKey as String: 160, 
        kCVPixelBufferHeightKey as String: 160
    ] as [String : Any]

    settings.previewPhotoFormat = previewFormat
    cameraOutput.capturePhoto(with: settings, delegate: self)
}

我有一个错误说:

Value of type 'AVCapturePhotoSettings' has no member 'availablePreviewPhotoPixelFormat'.

我正在使用 Xcode9 的测试版。

在 Beta 4 中,它被重命名为 __availablePreviewPhotoPixelFormat。我还没有看过 beta 5。

        var photoSettings: AVCapturePhotoSettings
        if #available(iOS 11.0, *) {
            photoSettings = AVCapturePhotoSettings.init(format: [AVVideoCodecKey: AVVideoCodecType.jpeg])
        } else {
            // Fallback on earlier versions
            photoSettings = AVCapturePhotoSettings()
            if photoSettings.__availablePreviewPhotoPixelFormatTypes.count > 0 {
                photoSettings.previewPhotoFormat = [kCVPixelBufferPixelFormatTypeKey as String : photoSettings.__availablePreviewPhotoPixelFormatTypes.first!]
            }
        }

我升级到 Xcode 12.0

后遇到了同样的问题

似乎 settings.availablePreviewPhotoPixelFormatTypes 在最终 Xcode 版本中再次更改为 settings.__availablePreviewPhotoPixelFormatTypes:版本 12.0 (12A7209)。我已经在没有 'rename' 的情况下使用它至少 2 年了。感谢@Matthijs Hollemans 的帮助

编辑: 这是关于此更改的官方回复: https://developer.apple.com/forums/thread/86810?answerId=259270022#259270022

此代码编译正常。

let settings = AVCapturePhotoSettings()
guard let previewPixelType = settings.__availablePreviewPhotoPixelFormatTypes.first else { return }
let previewFormat = [
    kCVPixelBufferPixelFormatTypeKey as String: previewPixelType,
    kCVPixelBufferWidthKey as String: 160,
    kCVPixelBufferHeightKey as String: 160
]
settings.previewPhotoFormat = previewFormat
output.capturePhoto(with: settings, delegate: self)