6

In new Xcode 12, there is an error: Value of type 'AVCapturePhotoOutput' has no member 'supportedFlashModes' when i try to reach https://developer.apple.com/documentation/avfoundation/avcapturephotooutput/1648766-supportedflashmodes Any suggestions?

Nike Kov
  • 12,630
  • 8
  • 75
  • 122
  • 1
    I'm having the same issue. Looks like it could have accidentally marked as private looking at this post: https://developer.apple.com/forums/thread/86810 – Andy Heard Sep 18 '20 at 11:31

4 Answers4

9

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
bguidolim
  • 367
  • 2
  • 9
1

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.

Nike Kov
  • 12,630
  • 8
  • 75
  • 122
0

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)

xaphod
  • 6,392
  • 2
  • 37
  • 45
0

You can try this:

let device2 = AVCapturePhotoOutput()

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

} else {
            
}
Parzival
  • 2,051
  • 4
  • 14
  • 32
Faiz Ul Hassan
  • 191
  • 1
  • 5