Migrate from Barcode Scanner 5.x#
Scandit Data Capture SDK 6.0 introduces all new APIs that are not backwards compatible with apps using ScanditSDK 5.x. To migrate your code to SDK 6.0 and newer, you will need to modify your app. This guide will assist you in performing this migration. In case you are unsure about how to perform the migration or the feature you are using is not covered in this migration guide, please reach out to us. We will gladly assist you in the upgrade process.
Before you start…
Replace the BarcodePicker#
In 5.x, the BarcodePicker (SBSBarcodePicker on iOS) was the central class that manages recognition, renders the video preview and provides means to configure what barcodes get scanned. In 6.0 and newer, there is no direct equivalent to the BarcodePicker. Instead this functionality is covered by multiple classes:
The SDCDataCaptureContext is the central object that manages the data capture/recognition process.
The SDCCamera class wraps the native camera on iOS.
The SDCDataCaptureView displays the camera preview as well as augmentations on top of the camera preview.
In your app you will need to use all of these classes to implement the functionality offered by the BarcodePicker. The following couple of lines show you how to do this. Take a look at Get Started With Barcode Scanning for more details, or check out one of our barcode capture samples.
// Create data capture context using your license key. context = DataCaptureContext(licenseKey: yourLicenseKey) // Set the back (world)-facing camera as the frame source of the context. camera = Camera.default context.setFrameSource(camera, completionHandler: nil) // See below for differences between 5.x and 6.x. let settings = BarcodeCaptureSettings() settings.set(symbology: .ean13UPCA, enabled: true) // Create new barcode capture mode with the settings from above. barcodeCapture = BarcodeCapture(context: context, settings: settings) // Register self as a listener to get informed whenever a new barcode got recognized. barcodeCapture.addListener(self) captureView = DataCaptureView(frame: view.bounds) captureView.dataCaptureContext = context captureView.autoresizingMask = [.flexibleWidth, .flexibleHeight] view.addSubview(captureView) overlay = BarcodeCaptureOverlay(barcodeCapture: barcodeCapture) captureView.addOverlay(overlay)
Start/Stop the Capture Process#
In 5.x the scan process was started by calling startScanning on the BarcodePicker. In 6.0+, the equivalent functionality is to switch the frame source from off to on and to enable the capture mode. Capture modes are enabled by default, the first line to enable the capture mode is only required when you are reusing a previously disabled data capture mode.
barcodeCapture.isEnabled = true camera?.switch(toDesiredState: .on)
To pause the barcode capture process, simply set the SDCBarcodeCapture.enabled property to NO (without turning the camera off). To resume the capture process, set the SDCBarcodeCapture.enabled property back to YES.
To stop the barcode capture process and turn the camera off, disable the capture mode and turn the camera off, as shown below:
barcodeCapture.isEnabled = false camera?.switch(toDesiredState: .off)
Barcode Scanner Changes Between 5.x and 6.0+#
The default code duplicate filter has been changed from 500ms to 0ms. This means that a barcode that gets scanned in two consecutive scans will get reported twice. When you pause/stop the scanning as soon as one code gets scanned, the code duplicate filtering setting does not affect you. However if you continue scanning further codes without pausing/stopping recognition, you may want to change the SDCBarcodeCaptureSettings.codeDuplicateFilter property back to 500ms.
EAN13 and UPCA used to be separate symbologies in 5.x but have now been merged into one symbology called SDCSymbologyEAN13UPCA.
The leading zero of UPCA codes is no longer removed by default. If you rely on this behavior in your app, you can either remove the leading zero yourself, or enable the “remove_leading_upca_zero” extension:
settings.settings(for: .ean13UPCA)?.set(extension: "remove_leading_upca_zero", enabled: true)
The API to configure the active scan area has been overhauled and simplified. If you were changing the active scan area to match the visible part of the preview, the good news is that the active scan area is now automatically restricted to the visible part of the preview. If you are restricting the scan area for other reasons, take a look at Set up the Active Scan Area and Location Selection to see how to upgrade your app.
The camera-related settings have been moved from ScanSettings to SDCCameraSettings. For example, if you want to change the preview resolution from 720p to 1080p, set the SDCCameraSettings.preferredResolution to SDCVideoResolutionFullHD and apply the new settings to the camera.
Migrate the Scan UI#
Without any further configuration, the default UI renders the “Scanning by Scandit” logo in the bottom-right corner of the data capture view. To replicate the default look from 5.x, you need to create a viewfinder. This functionality is only available for barcode capture, but not barcode tracking (MatrixScan).
Enable the Rectangular Viewfinder#
To enable the rectangular viewfinder (previously called the default viewfinder), use the following lines of code:
let overlay = BarcodeCaptureOverlay(barcodeCapture: barcodeCapture) let viewfinder = RectangularViewfinder() overlay.viewfinder = viewfinder captureView.addOverlay(overlay)
To change the size of the viewfinder using sizes relative to the data capture view (same as in 5.x), you can use the following lines of code:
viewfinder.setSize(SizeWithUnit(width: FloatWithUnit(value: 0.8, unit: .fraction), height: FloatWithUnit(value: 0.4, unit: .fraction)))
Enable the Laserline Viewfinder#
To enable the laserline viewfinder use the following lines of code:
let overlay = BarcodeCaptureOverlay(barcodeCapture: barcodeCapture) let viewfinder = LaserlineViewfinder() overlay.viewfinder = viewfinder captureView.addOverlay(overlay)
To change the width of the laserline relative to the data capture view (same as in 5.x), you can use the following line of code:
viewfinder.width = FloatWithUnit(value: 0.8, unit: .fraction)