DataScannerViewController
An object that scans the camera live video for text, data in text, and machine-readable codes.
Declaration
@MainActor @objc class DataScannerViewControllerMentioned in
Overview
Use a DataScannerViewController object to get input from physical objects that appear in the camera’s live video, such as printed text and QR codes on packages.
Create a data scanner by passing parameters that configure the interface to the init(recognizedDataTypes:qualityLevel:recognizesMultipleItems:isHighFrameRateTrackingEnabled:isPinchToZoomEnabled:isGuidanceEnabled:isHighlightingEnabled:) initializer. Then set its delegate to an object in your app that implements the DataScannerViewControllerDelegate protocol.
Before presenting the view controller, check whether the data scanner is available using the isSupported and isAvailable properties. Before you can use the data scanner, you must provide a reason for using the camera (add the NSCameraUsageDescription key to the information property list), and a person must agree when the system dialog first appears.
Then begin data scanning by invoking the startScanning() method and implement the dataScanner(_:didTapOn:) and similar delegate methods to handle user actions. Use the RecognizedItem parameter passed to these methods to perform data-specific actions. For example, if the item is a QR code, perform an action with its payload string, such as opening a URL in a browser, or calling a phone number.
Alternatively, you can track items that appear in the live video using the asynchronous recognizedItems array.
Topics
Handling availability
isSupportedisAvailablesupportedTextRecognitionLanguagesDataScannerViewController.ScanningUnavailable
Creating data scanners
init(recognizedDataTypes:qualityLevel:recognizesMultipleItems:isHighFrameRateTrackingEnabled:isPinchToZoomEnabled:isGuidanceEnabled:isHighlightingEnabled:)recognizedDataTypesDataScannerViewController.RecognizedDataType
Configuring data scanners
delegatequalityLevelDataScannerViewController.QualityLevelrecognizesMultipleItemsisHighFrameRateTrackingEnabledisPinchToZoomEnabledisGuidanceEnabledisHighlightingEnabled