LogicFlow
LogicFlow

Reputation: 103

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)
}

I have an error saying:

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

I'm using the beta version of Xcode 9.

Upvotes: 10

Views: 2911

Answers (3)

eharo2
eharo2

Reputation: 2642

I experienced the same problem after upgrading to Xcode 12.0

It seems that settings.availablePreviewPhotoPixelFormatTypes has been changed to settings.__availablePreviewPhotoPixelFormatTypes again in the Final Xcode Release: Version 12.0 (12A7209). I have been using it without the 'rename' for at least 2 years. Thx to @Matthijs Hollemans for the help

EDIT: This is the official response with regards to this change: https://developer.apple.com/forums/thread/86810?answerId=259270022#259270022

This code compiles OK.

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)

Upvotes: 5

user501836
user501836

Reputation: 1186

        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!]
            }
        }

Upvotes: 1

Matthijs Hollemans
Matthijs Hollemans

Reputation: 7892

In beta 4 this got renamed to __availablePreviewPhotoPixelFormat. I haven't looked at beta 5 yet.

Upvotes: 13

Related Questions