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 theBarcodeScannerManager
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 ofDataScannerViewController.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 tofalse
.serviceUUID
Optional: 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’sstatus
will be updated based on the outcome of these operations.
Throws
AScannerError
if the selected scanner type is not available or if itsstartMonitoring()
method fails.Declaration
Swift
@MainActor public func setActiveScanner(_ type: ScannerType?) async throws
Parameters
type
The
ScannerType
to activate. Passnil
to 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.notAvailable
if no scanner is active, or aScannerError
from 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
pairingImage
published property is updated with the result.Declaration
Swift
@MainActor public func getPairingQRCode() -> Image?
Return Value
A SwiftUI
Image
for pairing, ornil
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
, ornil
. -
Specifically retrieves the
VisionKitScanner
instance if it is the active scanner.Declaration
Swift
@MainActor public func getVisionKitScanner() -> VisionKitScanner?
Return Value
The
VisionKitScanner
instance, ornil
if VisionKit is not active or not the current scanner type. -
Returns an array of
ScannerType
s that are considered available on the device.Declaration
Swift
@MainActor public func availableScannerTypes() -> [ScannerType]
Return Value
An array of available
ScannerType
s. -
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)