I have made an ingredient scanning app in Swift using the WeScan git repo as I only want to scan one image at a time and found issues trying to use native libraries.
https://github.com/WeTransfer/WeScan/
Everything is complete however I was testing on an older iPhone with only 1 rear camera. After testing on an iPhone 15 I have realised the rear camera is not auto focusing and I can’t see in the library where to define either which camera to use (it needs the closest vision one for scanning small text) or how to make it auto focus (eg like in the native camera app you tap to auto focus and it will swap to the appropriate camera).
I have been playing around with the ImageScannerController and CameraScannerViewController to no avail trying to find an autoFocus or selectCamera method.
func scanFromCamera() {
let scannerViewController = ImageScannerController()
scannerViewController.imageScannerDelegate = self
scannerViewController.modalPresentationStyle = .popover
scannerViewController.navigationBar.backgroundColor = .black
scannerViewController.navigationBar.tintColor = .white
scannerViewController.toolbar.backgroundColor = .black
present(scannerViewController, animated: true)
}
private func configureOCR() {
ocrRequest = VNRecognizeTextRequest { (request, error) in
guard let observations = request.results as? [VNRecognizedTextObservation] else { return }
var ocrText = ""
for observation in observations {
guard let topCandidate = observation.topCandidates(1).first else { return }
ocrText += topCandidate.string + "\n"
}
DispatchQueue.main.async {
self.scannedIngedients = ocrText;
self.performSegue(withIdentifier: "ScanResults", sender: self)
}
}
ocrRequest.recognitionLevel = .accurate
ocrRequest.recognitionLanguages = ["en-US", "en-GB", "en-AU"]
ocrRequest.usesLanguageCorrection = true
}
private func processImage(_ image: UIImage) {
guard let cgImage = image.cgImage else { return }
let requestHandler = VNImageRequestHandler(cgImage: cgImage, options: [:])
do {
try requestHandler.perform([self.ocrRequest])
} catch {
print(error)
}
}
@objc func openCamera(sender: Any) {
scanFromCamera()
}
Thanks very much.




