1. Swift
  2. Price Tags

Swift

Price Tags

The Vision SDK supports on-device AI scanning for Price Tags, allowing you to extract structured data such as price, currency, and product information directly from item tags—without requiring an internet connection.

⚙️ SDK Configuration

To enable on-device scanning for price tags, 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 has been set, you can start scanning price tags using the following method:

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

      

📦 Delegate Method for Price Tag Values

When a price tag is successfully scanned, the following delegate method is called:

        func codeScannerViewDidCapturePrice(_ price: String, withSKU sKU: 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)

let priceTagDetectionSettings = CodeScannerView.PriceTagDetectionSettings()
priceTagDetectionSettings.shouldDisplayOnScreenIndicators = true // Display one screen indicators
priceTagDetectionSettings.validTagImage = UIImage(named: "validImage")
scannerView.setPriceTagDetectionSettingsTo(priceTagDetectionSettings)

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

scannerView.startRunning() // Start scanning

// Delegate callback for scanned barcodes

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

}

func codeScannerViewDidCapturePrice(_ price: String, withSKU sKU: String) -> Bool {
    // Perform matching with your data store
    return true
}