Recognize live text and machine-readable codes with VisionKit.
One.iOS.DataScannerViewController wraps VisionKit’s live data scanner on iOS.
Check the SDK’s isSupported and isAvailable before presenting. Set
ios.infoPlist.NSCameraUsageDescription. Recognition requires supported
physical hardware; the simulator reports unsupported.
import { One } from 'one'
const Scanner = One.iOS.DataScannerViewControllerif (Scanner.isSupported && Scanner.isAvailable) { const scanner = new Scanner({ recognizedDataTypes: [Scanner.RecognizedDataType.text(), Scanner.RecognizedDataType.barcode()], recognizesMultipleItems: true, }) scanner.delegate = { dataScanner: (sender, event) => { if ('didTapOn' in event) { sender.stopScanning() void sender.dismiss() } }, } await scanner.present() scanner.startScanning() for await (const items of scanner.recognizedItems) { // consume each native batch in SDK reading order. if (items.length > 0) break } scanner.stopScanning() await scanner.dismiss()}The initializer uses an options object for Swift’s labeled arguments. The
recognized-data-type set is an array deduplicated by the native SDK.
RecognizedDataType.text(languages = [], textContentType?) and
RecognizedDataType.barcode(symbologies = []) mirror the SDK factories. Barcode
symbologies use Vision raw string values, such as QR. Text content types are
dateTimeDuration, emailAddress, flightNumber, fullStreetAddress,
shipmentTrackingNumber, telephoneNumber, URL, and currency.
recognizedItems is an AsyncIterable<RecognizedItem[]> backed by the native
AsyncStream. Each iterator owns a subscription; breaking a for await loop
cancels it. Consumers using next() directly must call return() to cancel.
It delivers complete ordered batches, including empty batches, without
fabricating recognition or deriving snapshots from delegate callbacks.
stopScanning() pauses recognition; cancellation of iteration is separate.
Delegate labeled overloads adapt to dataScanner(sender, event) with
didTapOn, didAdd, didUpdate, didRemove, or becameUnavailableWithError.
Add/update/remove events include allItems. dataScannerDidZoom(sender)
preserves the separate SDK method. Unavailability preserves unsupported and
cameraRestricted enum cases; operation rejection uses
E_DATA_SCANNER_UNSUPPORTED and E_DATA_SCANNER_CAMERA_RESTRICTED.
Recognized items are tagged objects with type, UUID-string id, and bounds
containing topLeft, topRight, bottomRight, bottomLeft points. Text items
have transcript; barcodes have optional payloadStringValue. The native
Vision observation objects and UIKit overlayContainerView are not bound.
This is a scanner subset, not the complete Vision or UIView API.
present and dismiss adapt UIViewController ownership to the app’s current
presenter. They resolve after the transition. Start scanning explicitly after
presentation. Dismissal stops scanning; a delegate event does not dismiss the
scanner. capturePhoto() returns the same native UIImage encoding subset as
document camera, with PNG/JPEG ArrayBuffer output.
regionOfInterest is a CGRect-shaped { x, y, width, height } in view points;
undefined clears it. Zoom factors use SDK units.
| Availability | Type | Description |
|---|---|---|
isSupportedbooleanStatic SDK hardware support. | boolean | Static SDK hardware support. |
isAvailablebooleanStatic SDK camera availability. | boolean | Static SDK camera availability. |
supportedTextRecognitionLanguagesstring[]Static SDK language identifiers. | string[] | Static SDK language identifiers. |
| Initializer configuration | Type | Description |
|---|---|---|
recognizedDataTypesDataScannerRecognizedDataType[]Required text and barcode filters. | DataScannerRecognizedDataType[] | Required text and barcode filters. |
qualityLevelDataScannerQualityLevelbalanced by default; also fast or accurate. | DataScannerQualityLevel | balanced by default; also fast or accurate. |
recognizesMultipleItemsbooleanDefaults to false. | boolean | Defaults to false. |
isHighFrameRateTrackingEnabledbooleanDefaults to true. | boolean | Defaults to true. |
isPinchToZoomEnabledbooleanDefaults to true. | boolean | Defaults to true. |
isGuidanceEnabledbooleanDefaults to true. | boolean | Defaults to true. |
isHighlightingEnabledbooleanDefaults to false. | boolean | Defaults to false. |
All configuration properties are readonly after initialization. Except for
recognizedDataTypes, initializer fields are optional and use the defaults
above.
| Controller | Type | Description |
|---|---|---|
delegateDataScannerViewControllerDelegate | nullNative scanner events; defaults to null. | DataScannerViewControllerDelegate | null | Native scanner events; defaults to null. |
regionOfInterestDataScannerRect | undefinedScan region in view points. | DataScannerRect | undefined | Scan region in view points. |
isScanningbooleanNative scanning state. | boolean | Native scanning state. |
minZoomFactornumberSDK minimum supported zoom. | number | SDK minimum supported zoom. |
maxZoomFactornumberSDK maximum supported zoom. | number | SDK maximum supported zoom. |
zoomFactornumberCurrent camera zoom. | number | Current camera zoom. |
recognizedItemsAsyncIterable<RecognizedItem[]>Native async stream of complete batches. | AsyncIterable<RecognizedItem[]> | Native async stream of complete batches. |
present(animated?: boolean) => Promise<void>Presents the scanner; animation defaults to true. | (animated?: boolean) => Promise<void> | Presents the scanner; animation defaults to true. |
dismiss(animated?: boolean) => Promise<void>Stops scanning and dismisses; animation defaults to true. | (animated?: boolean) => Promise<void> | Stops scanning and dismisses; animation defaults to true. |
startScanning() => voidStarts native recognition or throws. | () => void | Starts native recognition or throws. |
stopScanning() => voidStops recognition. | () => void | Stops recognition. |
capturePhoto() => Promise<UIImage>Captures a high-resolution native image. | () => Promise<UIImage> | Captures a high-resolution native image. |
Sources: DataScannerViewController, recognizedItems. Simulator unsupported rejection is covered by a fixture and production Swift SDK probe. Generated Nitro ABI integration and physical text/barcode recognition, tracking, taps, zoom, capture and permissions remain acceptance gates under the native CI owner.
Edit this page on GitHub.