twostraws / CodeScanner

A SwiftUI view that is able to scan barcodes, QR codes, and more, and send back what was found.
MIT License
1.01k stars 286 forks source link

iPhone 14 Focus Distance #89

Closed MikeMilzz closed 6 months ago

MikeMilzz commented 1 year ago

With the change in minimal focal distance on the standard camera with iPhone 14, I've found it harder to scan smaller barcodes. I have read articles about trying to force the macro camera / mode. Have others noticed the same issue or found ways around it?

ebi commented 1 year ago

This happens on iPhone 13 Pro aswell

ariarora14 commented 1 year ago

I have also experienced this issue. There is usually an autofocus enabled property in AVFoundation but Im not sure how to access it and edit it and if that is even possible. @twostraws Any help with this one please?

MikeMilzz commented 1 year ago

I'm testing another barcode scanner and here is what I did to resolve the issue. I had to limit it to iPhone because it was causing issues on iPad and macOS so be careful where you use .builtInUltraWideCamera but this will help with the focus distance.

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

nathanfallet commented 1 year ago

Maybe conditionally select the camera when instantiating can solve the problem? Feel free to try to make a PR if you find something

ariarora14 commented 1 year ago

@MikeMilzz where did you add the discoverySession in the context of the current library?

bennokress commented 1 year ago

I have opened a PR that uses the Ultra Wide Camera if available for the current device as a default parameter of the CodeScanner. It's a combination of what was proposed in previous comments here.

IfThenDev commented 1 year ago

I believe this issue was resolved with the patches above but in the meantime I've found more info that the following devices might be the more up-to-date solutions.

AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInTripleCamera, .builtInDualWideCamera, .builtInUltraWideCamera, .builtInWideAngleCamera, .builtInTrueDepthCamera], mediaType: AVMediaType.video, position: cameraPosition)