Not sure which Scandit product fits your use case?
Install our data-capture-sdk skill so your coding agent can answer questions about Scandit products and recommend the right one for your use case, directly from your editor. More info →
Run this in a terminal in your project directory, then follow the instructions to select your coding agent.
npx skills add https://github.com/scandit/skills --skill data-capture-sdkYour coding agent loads the skill automatically based on your prompt; to invoke it explicitly, call /data-capture-sdk followed by your task.
Get Started
In this guide you will learn step-by-step how to add Smart Label Capture to your application.
The general steps are:
- Create a view controller
- Initialize the Data Capture context
- Initialize the Label Capture mode
- Implement a listener to handle captured labels
- Visualize the scan process
- Start the camera
- Provide feedback
Prerequisites
Before starting with adding a capture mode, make sure that you have a valid Scandit Data Capture SDK license key and that you have added the necessary dependencies. If you have not done that yet, check out this guide.
You can retrieve your Scandit Data Capture SDK license key by signing in to your account Dashboard.
Module Overview
The modules that need to be included in your project depend on the features you want to use:
| Module | Required for Feature |
|---|---|
| ScanditCaptureCore | Always required |
| ScanditBarcodeCapture | Always required |
| ScanditLabelCapture | Always required |
| ScanditLabelCaptureText | Required for capturing arbitrary texts |
| ScanditPriceLabel | Required for capturing price texts |
Create a view controller
import ScanditLabelCapture
class YourScanViewController: UIViewController {
private var context: DataCaptureContext!
private var labelCapture: LabelCapture!
private var dataCaptureView: DataCaptureView!
private var labelCaptureOverlay: LabelCaptureBasicOverlay!
private var camera: Camera?
override func viewDidLoad() {
super.viewDidLoad()
/* Initialize the components as lined out in the following sections */
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
/* Start the camera */
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
/* Stop the camera, disable capture mode */
}
// ...
}
Initialize the Data Capture Context
The first step to add capture capabilities to your application is to create a new Data Capture Context. The context expects a valid Scandit Data Capture SDK license key during construction.
- Swift
- Objective-C
self.context = DataCaptureContext(licenseKey: "-- ENTER YOUR SCANDIT LICENSE KEY HERE --")
SDCDataCaptureContext *dataCaptureContext = [SDCDataCaptureContext contextForLicenseKey:@"-- ENTER YOUR SCANDIT LICENSE KEY HERE --"];
Initialize the Label Capture Mode
The main entry point for the Label Capture Mode is the LabelCapture object.
It is configured through LabelCaptureSettings and allows you to register one or more listeners that get informed whenever a new frame has been processed.
let labelDefinition: LabelDefinition = {
/*
* Add a barcode field with the expected symbologies and pattern.
* You can omit the pattern if the content of the barcode is unknown.
*/
let barcodeField = CustomBarcode(
name: "<your-barcode-field-name>",
symbologies: [
NSNumber(value: Symbology.ean13UPCA.rawValue),
NSNumber(value: Symbology.code128.rawValue)
]
)
barcodeField.patterns = ["\\d{12,14}"]
/*
* Add a text field for capturing expiry dates.
* The field is set as optional so that the capture can complete
* even if the expiry date is not present or not readable.
*/
let expiryDateField = ExpiryDateText(name: "<your-expiry-date-field-name>")
expiryDateField.optional = false
return LabelDefinition(
name: "<your-label-name>",
fields: [barcodeField, expiryDateField]
)
}()
guard let labelCaptureSettings = try? LabelCaptureSettings(
labelDefinitions: [labelDefinition]
) else {
/*
* Creating label capture settings can fail if the label definitions are invalid.
* You can handle the error here.
*/
}
/*
* Create the label capture mode with the settings
* and data capture context created earlier
*/
labelCapture = LabelCapture(context: context, settings: labelCaptureSettings)
/*
* Add a listener to the label capture mode, see the following section
* for more information on implementing the listener
*/
labelCapture.addListener(self)