1. Swift
  2. Item Retrieval

Swift

Item Retrieval

The Vision SDK supports on-device AI scanning for Item Retrieval, allowing you to retrieve items in a from a shelf or stack of items in a warehouse environment without requiring an internet connection.

⚙️ SDK Configuration

To enable on-device scanning for item retrieval, you must first check for feature availability using the method below. This setup is required before any image processing.

        

let error = await VisionAPIManager.shared.checkScanningFeatureAuthenticationWithKey("your-api-key")
                
if let error = error {
                    
    self.showAlert(code: error.localizedDescription) {
                        
    }
}


      

💡 You must provide either an apiKey or a valid token during configuration.


📸 Extracting Data from an Image

Once the permission has been set, you can start item retrieval mode scanning using the following method:

        scannerView.configure(
    delegate: VisionSDK.CodeScannerViewDelegate,
    sessionPreset: .high,
    captureMode: .manual,
    captureType: .single,
    scanMode: .itemRetrieval
)

      

📦 Delegate Method for Price Tag Values

When an item is successfully scanned, the following delegate method is called:

        func codeScannerViewDidCaptureItemCodesWith(_ codes: [String]) -> [String: Bool]

      

❗️Error Handling Delegate

If an error occurs during the price tag scanning process, the following delegate method will be triggered. You can implement this to handle any failures gracefully.

        func codeScannerView(_ scannerView: VisionSDK.CodeScannerView, didFailure error: NSError)

      

Use this method to log errors, display messages to the user, or perform recovery actions when scanning fails.


Sample Code

        
import VisionSDK

let scannerView = CodeScannerView(frame: view.bounds)

self.view.addSubview(scannerView)

scannerView.configure(
    delegate: VisionSDK.CodeScannerViewDelegate,
    sessionPreset: AVCaptureSession.Preset = .high,
    captureMode: VisionSDK.CaptureMode = .auto, 
    captureType: VisionSDK.CaptureType = .single, 
    scanMode: VisionSDK.CodeScannerMode = .itemRetrieval)

scannerView.startRunning() // Start scanning

// Delegate callback for scanned barcodes

func codeScannerView(_ scannerView: CodeScannerView, didFailure error: NSError) {

}

func codeScannerViewDidCaptureItemCodesWith(_ codes: [String]) -> [String: Bool] {
    // Perform matching with your data store and send true for item that are matched for screen display
    return [:]
}