Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 979
LogicFlow Avatar asked Aug 08 '17 06:08

LogicFlow


Video Answer


3 Answers

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

like image 88
Matthijs Hollemans Avatar answered Nov 11 '22 20:11

Matthijs Hollemans


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)
like image 34
eharo2 Avatar answered Nov 11 '22 20:11

eharo2


        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!]
            }
        }
like image 36
user501836 Avatar answered Nov 11 '22 18:11

user501836