OCTAVIAN
OCTAVIAN

Reputation: 336

How do I access the camera in Swift 4?

Trying to run this code which scans a barcode/QR however whenever I try I keep getting this error "Failed to get the camera device", not sure what part of the code to post since I have no idea where the error comes from, I have the correct settings in info.plist since I've added Privacy - camera usage, and photo library usage, the code is unchanged from this file. Does it run for anyone else? I am testing on my device.

https://github.com/appcoda/QRCodeReader

Upvotes: 0

Views: 564

Answers (1)

SSSS
SSSS

Reputation: 310

You need to change the type of camera, so on line 40 in QRScannerController.swift class change [.builtInDualCamera] to [.builtInWideAngleCamera], this is the common camera. This should fix your problem.

let deviceDiscoverySession = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInDualCamera], mediaType: AVMediaType.video, position: .back)

Answer found here: https://github.com/appcoda/QRCodeReader/issues/3

Upvotes: 4

Related Questions