fix(ios): focus close-range barcodes on iPhone Pro cameras#136
Draft
masanggil1986 wants to merge 1 commit into
Draft
fix(ios): focus close-range barcodes on iPhone Pro cameras#136masanggil1986 wants to merge 1 commit into
masanggil1986 wants to merge 1 commit into
Conversation
The iOS scanner hard-coded the built-in wide-angle camera, whose minimum focus distance on iPhone Pro models (~15-20cm) is longer than the natural barcode scanning distance, so codes held close never come into focus. Prefer a virtual multi-camera device (triple / dual-wide) when available so the system can switch to the ultra-wide lens for macro focus; frame it at the standard wide zoom and restrict autofocus to the near range. Focus is configured after the session starts, since starting a session can change the active format and reset videoZoomFactor. Every setting is capability-gated, so single-lens devices behave exactly as before.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Problem
On iPhone Pro models the rear wide-angle camera has a longer minimum focus distance (~15–20 cm) than the distance at which users naturally hold a barcode. The iOS scanner hard-codes
AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInWideAngleCamera], …), so codes held close never come into focus and can't be scanned. Non-Pro iPhones focus closer, so they're unaffected — which is why this only reproduces on Pro devices.Fix
.builtInTripleCamera→.builtInDualWideCamera→.builtInWideAngleCamera). Virtual devices let iOS automatically switch to the ultra-wide lens for macro focus when the subject is closer than the wide lens can handle.videoZoomFactorto the device's firstvirtualDeviceSwitchOverVideoZoomFactorsvalue (instead of the 0.5× ultra-wide view), while still allowing the automatic macro switch for close subjects.autoFocusRangeRestriction = .near+.continuousAutoFocus.startRunning()— starting a session can change the active format, which resetsvideoZoomFactor— and re-applied when switching back to the rear camera.Camera selection is shared by the initial setup and the switch-camera button via
preferredBackCamera(); focus configuration lives inenableCloseFocus(on:).Backward compatibility
#available(iOS 13.0, *),isAutoFocusRangeRestrictionSupported,isFocusModeSupported, emptyvirtualDeviceSwitchOverVideoZoomFactors), so single-lens devices (e.g. iPhone SE) keep the exact previous behavior.#available.Testing