Error setting up camera using DiscoverySession

Trying to access camera hardware using

 let deviceDiscoverySession = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInWideAngleCamera], mediaType: AVMediaType.video, position:  AVCaptureDevice.Position.front)

  guard let captureDevice = deviceDiscoverySession.devices.first else {
         print("Failed to get the camera device")
}

In many devices I get the Failed to get camera device error.

Devices like

  • iPhone XS
  • iPhone X
  • iPhone 7
  • iPhone 11
  • iPhone 11 Pro Max
  • iPhone 8
  • iPhone14,7
  • iPhone 12
  • iPhone XR
  • iPhone SE (2nd generation)
  • iPhone 13
  • iPhone 13 Pro
  • iPhone 6s
  • iPhone 6s Plus

Is there a reason why this might happen if the hardware is functioning properly. Please help as a lot of users are facing this issue.

I wasn't able to reproduce the issue using your code, I recommend that you file a bug report for the issue. It would be interesting to know if the devices property is ever populated with devices or not, you could key-value observe it to find out.

@gchiste Yes even I was not able to reproduce this issue with the same code in the listed device, but its happening for people. The same exact model works for some people, for some people its returning this error. They are not able to proceed forward, we checked that their hardware is also functioning properly.

Will file a bug report for this

Error setting up camera using DiscoverySession
 
 
Q