BarcodeScannerManager

@MainActor
public final class BarcodeScannerManager : ObservableObject
extension BarcodeScannerManager: BarcodeScannerDelegate

Undocumented

  • A shared singleton instance of the BarcodeScannerManager for 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 .scanning state.

    Declaration

    Swift

    @Published
    @MainActor
    public private(set) var isScanning: Bool { get set }
  • A SwiftUI Image containing 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 String parameter contains the decoded barcode data.

    Declaration

    Swift

    @MainActor
    public var onBarcodeScanned: ((String) -> Void)?
  • A callback closure that is invoked when the status of the BarcodeScannerManager changes.

    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

    recognizedDataTypes

    For VisionKitScanner, a set of DataScannerViewController.RecognizedDataType to detect (e.g., [.barcode()], [.text()]). Defaults to [.barcode()].

    recognizesMultipleItems

    For VisionKitScanner, a Boolean indicating whether the scanner should continue scanning after detecting an item. Defaults to false.

    serviceUUID

    Optional: For IPCMobileScanner, a custom Bluetooth service UUID string. If nil, the IPCMobile SDK’s default service UUID will be used.

  • setActiveScanner(_:) Asynchronous

    Sets and activates the specified scanner type.

    This method will:

    1. Stop and deactivate any currently active scanner.
    2. Set the new scanner type as active.
    3. Call startMonitoring() on the new active scanner instance. The manager’s status will be updated based on the outcome of these operations.

    Throws

    A ScannerError if the selected scanner type is not available or if its startMonitoring() method fails.

    Declaration

    Swift

    @MainActor
    public func setActiveScanner(_ type: ScannerType?) async throws

    Parameters

    type

    The ScannerType to activate. Pass nil to deactivate all scanners.

  • startMonitoring() Asynchronous

    Starts 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() Asynchronous

    Triggers a scan operation on the currently active scanner.

    Behavior depends on the active scanner type:

    • VisionKitScanner: Starts the DataScannerViewController‘s scanning process.
    • Hardware scanners (ProGlove, IPCMobile): Typically hardware-triggered.

    Throws

    ScannerError.notAvailable if no scanner is active, or a ScannerError from the active scanner’s triggerScan().

    Declaration

    Swift

    @MainActor
    public func triggerScan() async throws
  • Retrieves a pairing QR code from the active scanner, if supported (e.g., ProGlove, IPCMobile). The pairingImage published property is updated with the result.

    Declaration

    Swift

    @MainActor
    public func getPairingQRCode() -> Image?

    Return Value

    A SwiftUI Image for pairing, or nil if 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

    data

    The ScannerDisplayData to send (e.g., .proGlove(...), .ipcMobile(...)).

  • Retrieves the UIViewController for the active scanner’s UI, if applicable (primarily for VisionKit).

    Declaration

    Swift

    @MainActor
    public func getScannerView() -> UIViewController?

    Return Value

    The scanner’s UIViewController, or nil.

  • Specifically retrieves the VisionKitScanner instance if it is the active scanner.

    Declaration

    Swift

    @MainActor
    public func getVisionKitScanner() -> VisionKitScanner?

    Return Value

    The VisionKitScanner instance, or nil if 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 onBarcodeScanned callback with the barcode data.

    Declaration

    Swift

    @MainActor
    public func barcodeScannerDidReceiveBarcode(_ barcode: String, from scanner: any BarcodeScanner)