Swift
Single Barcode Scanning
Single barcode scanning allows you to detect and process one barcode at a time within a predefined scanning window. This ensures precise detection by limiting the scan area, improving accuracy and performance.
⚙️ Configure the SDK
To enable single barcode scanning, you need to configure the Vision SDK using the configure method:
🤖 Auto Mode Barcode Scanning
For automatic barcode capture, set the captureMode to .auto:
Configuration example:
✋ Manual Mode Barcode Scanning
For manual barcode capture, set the captureMode to .manual:
Configuration example:
🎯 Focus Area Configuration
To define the scan region, use the focusImageRect parameter:
This helps confirm the scanning region visually during development or debugging.
🧭 Detection Indicators
To receive detection indicators (without actual values), implement the following delegate method:
text: Indicates presence of textbarCode: Indicates presence of a barcodeqrCode: Indicates presence of a QR codedocument: Indicates presence of a document
🔘 Enable Detection Indicators
You can toggle detection indicators as follows:
You can also control whether image sharpness scoring runs, using isImageSharpnessIndicationOn (default false on iOS, since it's a new, opt-in flag that adds an extra Neural Engine/CPU cost most consumers don't need):
Platform difference: on Android, this same flag existed before and defaults to true to preserve historical behavior for existing consumers. On iOS it's new in v2.3.13 and defaults to false. If you support both platforms, set this flag explicitly rather than relying on the default.
⏸️ Pausing and Resuming Detection
Available since v2.3.13. Use pauseDetection() and resumeDetection() to temporarily stop all detection work (barcode, text, document, and sharpness) while keeping the camera preview and session running:
This is different from stopping the camera entirely. pauseDetection() keeps the live preview visible and the session active, so resuming is instant, there's no camera restart flicker, and no permission or session setup work needs to happen again. It's intended for short-lived UI states (a loading spinner, a result screen) where you don't want the camera doing analysis work in the background, but you also don't want to tear the session down.
While paused:
- No detection callbacks fire (
codeScannerViewDidDetect, barcode/document/text results, sharpness updates). - Any bounding boxes or detection indicators currently on screen are cleared immediately.
- Any in-progress price tag detection is cancelled rather than left to finish in the background.
Switching scanMode automatically resumes detection even if it was previously paused, since changing modes rebuilds the underlying scanner. If your UI has a manual pause toggle, resync it to "on" when the user changes scan mode.
📦 Delegate Method for Barcode Values
When a barcode is successfully scanned, the following delegate method is called:
❗️Error Handling Delegate
If an error occurs during the barcode scanning process, the following delegate method will be triggered. You can implement this to handle any failures gracefully.
Use this method to log errors, display messages to the user, or perform recovery actions when scanning fails.
🧾 Barcode Object Structure
The DetectedBarcode object returned in the delegate contains the following properties: