Xcode 12. Value of type 'AVCapturePhotoOutput' has no member 'supportedFlashModes'

Viewed 1061
4 Answers

Seems to be a bug on Xcode 12, but you can workaround it using macro conditions:

#if !targetEnvironment(simulator)
guard stillImageOutput?.supportedFlashModes.contains(mode) == true else { return }
//rest of your code
#endif

As @Andy Heard wrote:

Our apologies. For apps using Swift 3.2 or Swift 4.0, several AVFoundation capture APIs (public extensions on external protocol) were inadvertently marked private in Xcode 9.

The following AVFoundation API are temporarily unavailable:

  • AVCaptureDevice.Format.supportedColorSpaces

  • AVCaptureDevice.supportedFlashModes

  • AVCapturePhotoOutput.availablePhotoPixelFormatTypes

  • AVCapturePhotoOutput.availableRawPhotoPixelFormatTypes

  • AVCapturePhotoSettings.availablePreviewPhotoPixelFormatTypes

As a workaround you can use the SwiftPrivate versions of these API by prepending each API with double underscore (__). For example, change AVCaptureDevice.Format.supportedColorSpaces to AVCaptureDevice.Format.__supportedColorSpaces.

For the XCode 12 regression (sigh), you can use the __ version like so

    var flashModesSupported: [AVCaptureDevice.FlashMode] {
        #if targetEnvironment(simulator)
        return self.photoOutput.__supportedFlashModes.compactMap { AVCaptureDevice.FlashMode.init(rawValue: $0.intValue) }
        #else
        return self.photoOutput.supportedFlashModes
        #endif
    }

There was a report this did not trigger SPI (so, safe to submit to app store)

You can try this:

let device2 = AVCapturePhotoOutput()

if (device2.supportedFlashModes.contains(.auto)){

} else {
            
}
Related