1

I'm trying to create a QR code scanner with this tutorial

I don't get any devices.

let deviceDiscoverySession = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInDualCamera], mediaType: AVMediaType.video, position: .back)
print(deviceDiscoverySession.devices.isEmpty)//true

I checked similar questions

Question 1 - I didn't see App Sandbox in Target Settings / Capabilities

Question 2 - I'm running the project in iPhone 6 real device, Not in simulator. And AVCaptureDevice.authorizationStatus(for: AVMediaType.video) returns .authorized. I've added Camera access description in info.plist

arun siva
  • 809
  • 1
  • 7
  • 18

1 Answers1

2

Not all iPhones contain dual camera, that's why devices is empty.

You can try add this deviceTypes: [.builtInWideAngleCamera].

Here is all available device types for now.

Also there is a good answer to question about Dual Camera - check this.

Hope this will help you!

kzakharc
  • 499
  • 2
  • 8
vpoltave
  • 1,612
  • 3
  • 14
  • 31
  • Is it possible to use multiple deviceTypes with or condition. If dual camera isn't available use builtInWideAngleCamera? – arun siva May 16 '19 at 11:52
  • @arunsiva `DiscoverySession` init takes an array of `AVCaptureDevice.DeviceType`, so you can try desire options and see how it will play out. – vpoltave May 16 '19 at 12:41
  • @arunsiva I edited answer and add link to all available device types – vpoltave May 16 '19 at 13:08