BarcodeScannerManager
@MainActor
public final class BarcodeScannerManager : ObservableObject
extension BarcodeScannerManager: BarcodeScannerDelegate
Undocumented
-
A shared singleton instance of the
BarcodeScannerManagerfor convenient global access. Uses default initialization parameters.Declaration
Swift
@MainActor public static let shared: BarcodeScannerManager -
The currently active scanner type (e.g.,
.visionKit,.proGlove).Declaration
Swift
@Published @MainActor public private(set) var activeScannerType: ScannerType? { get set } -
The current overall status of the active scanner or the manager itself.
Declaration
Swift
@Published @MainActor public private(set) var status: ScannerStatus { get set } -
A Boolean indicating if the active scanner is currently in a
.scanningstate.Declaration
Swift
@Published @MainActor public private(set) var isScanning: Bool { get set } -
A SwiftUI
Imagecontaining the pairing QR code, if generated by the active scanner (e.g., ProGlove, IPCMobile).Declaration
Swift
@Published @MainActor public private(set) var pairingImage: Image? { get set } -
A callback closure that is invoked when a barcode is successfully scanned. The
Stringparameter contains the decoded barcode data.Declaration
Swift
@MainActor public var onBarcodeScanned: ((String) -> Void)? -
A callback closure that is invoked when the
statusof theBarcodeScannerManagerchanges.Declaration
Swift
@MainActor public var onStatusChanged: ((ScannerStatus) -> Void)? -
Initializes a new
BarcodeScannerManager.This setup allows for custom configuration of the internal scanners, particularly
VisionKitScanner.Declaration
Swift
@MainActor public init( recognizedDataTypes: Set<BarcodeDataType> = [.barcode()], recognizesMultipleItems: Bool = false, serviceUUID: String? = nil )Parameters
recognizedDataTypesFor
VisionKitScanner, a set ofDataScannerViewController.RecognizedDataTypeto detect (e.g.,[.barcode()],[.text()]). Defaults to[.barcode()].recognizesMultipleItemsFor
VisionKitScanner, a Boolean indicating whether the scanner should continue scanning after detecting an item. Defaults tofalse.serviceUUIDOptional: For
IPCMobileScanner, a custom Bluetooth service UUID string. Ifnil, the IPCMobile SDK’s default service UUID will be used. -
setActiveScanner(_:Asynchronous) Sets and activates the specified scanner type.
This method will:
- Stop and deactivate any currently active scanner.
- Set the new scanner type as active.
- Call
startMonitoring()on the new active scanner instance. The manager’sstatuswill be updated based on the outcome of these operations.
Throws
AScannerErrorif the selected scanner type is not available or if itsstartMonitoring()method fails.Declaration
Swift
@MainActor public func setActiveScanner(_ type: ScannerType?) async throwsParameters
typeThe
ScannerTypeto activate. Passnilto deactivate all scanners. -
startMonitoring()AsynchronousStarts monitoring on the currently active scanner.
Declaration
Swift
@MainActor public func startMonitoring() async throws -
Stops monitoring on the currently active scanner.
Declaration
Swift
@MainActor public func stopMonitoring() -
triggerScan()AsynchronousTriggers a scan operation on the currently active scanner.
Behavior depends on the active scanner type:
VisionKitScanner: Starts theDataScannerViewController‘s scanning process.- Hardware scanners (ProGlove, IPCMobile): Typically hardware-triggered.
Throws
ScannerError.notAvailableif no scanner is active, or aScannerErrorfrom the active scanner’striggerScan().Declaration
Swift
@MainActor public func triggerScan() async throws -
Retrieves a pairing QR code from the active scanner, if supported (e.g., ProGlove, IPCMobile). The
pairingImagepublished property is updated with the result.Declaration
Swift
@MainActor public func getPairingQRCode() -> Image?Return Value
A SwiftUI
Imagefor pairing, ornilif not supported or generation fails. -
Resets the currently active scanner to its initial state.
Declaration
Swift
@MainActor public func resetActiveScanner() -
Sends display data to the active scanner, if it supports screen updates.
Declaration
Swift
@MainActor public func updateScannerDisplay(data: ScannerDisplayData)Parameters
dataThe
ScannerDisplayDatato send (e.g.,.proGlove(...),.ipcMobile(...)). -
Retrieves the
UIViewControllerfor the active scanner’s UI, if applicable (primarily for VisionKit).Declaration
Swift
@MainActor public func getScannerView() -> UIViewController?Return Value
The scanner’s
UIViewController, ornil. -
Specifically retrieves the
VisionKitScannerinstance if it is the active scanner.Declaration
Swift
@MainActor public func getVisionKitScanner() -> VisionKitScanner?Return Value
The
VisionKitScannerinstance, ornilif VisionKit is not active or not the current scanner type. -
Returns an array of
ScannerTypes that are considered available on the device.Declaration
Swift
@MainActor public func availableScannerTypes() -> [ScannerType]Return Value
An array of available
ScannerTypes. -
Called by the active scanner when its status changes.
Declaration
Swift
@MainActor public func barcodeScannerDidUpdateStatus(_ newStatus: ScannerStatus, for scanner: any BarcodeScanner) -
Called by the active scanner when a barcode is successfully scanned. Invokes the manager’s
onBarcodeScannedcallback with the barcode data.Declaration
Swift
@MainActor public func barcodeScannerDidReceiveBarcode(_ barcode: String, from scanner: any BarcodeScanner)