Configure the barcode scan settings
When developing with BarcodeScannerViewController
, you can add configurations via the BarcodeScannerConfig
class. This page will guide you on how to configure the settings.
Barcode Decode Settings
Set the barcode format via APIs
Set the supported barcode format is always the first step when creating a barcode scanner. It improves the processing speed and the accuracy.
- Objective-C
- Swift
DSBarcodeScannerConfig *config = [[DSBarcodeScannerConfig alloc] init]; config.barcodeFormats = DSBarcodeFormatOneD | DSBarcodeFormatQRCode;
let config = BarcodeScannerConfig() config.barcodeFormats = [.oneD, .qrCode]
Setup a customized template file
A template file is a JSON file that includes a series of algorithm parameter settings. It is always used to customize the performance for different usage scenarios. Contact us to get a customized template for your scanner.
-
Create a DynamsoftResources folder in the finder. Under the DynamsoftResources folder create a new folder, Templates.
-
Put your .json template file under the Templates folder. Here we suppose you are adding a template file named ReadQRCodes.json.
-
Rename the DynamsoftResources folder’s extension name to .bundle and drag the DynamsoftResources.bundle into your project on Xcode. Select Create groups for the Added folders option.
-
Specify the template file via
templateFilePath
- Objective-C
- Swift
-
DSBarcodeScannerConfig *config = [[DSBarcodeScannerConfig alloc] init]; config.templateFilePath = @"ReadQRCodes.json";
-
let config = BarcodeScannerConfig() config.templateFilePath = "ReadQRCodes.json"
Related APIs
Configure the UI Elements
Barcode Scanner UI Components
- Close button: Stop barcode scanning and go back to the previous activity.
- Scan Region: Set a region of interest so that the algorithm focus on this region only. It can sharpenly improve the processing speed. For some special barcode types like DotCode the scan region improves the read-rate as well.
- Torch button: A clickable button that can turn on/off the torch.
- Scan Laser: A line that moving up and down. Its moving area is limited in the scan region.
- Objective-C
- Swift
DSBarcodeScannerConfig *config = [[DSBarcodeScannerConfig alloc] init]; config.isCloseButtonVisible = false; DSRect *region = [[DSRect alloc] init]; region.left = 0.15; region.top = 0.3; region.right = 0.85; region.bottom = 0.7; config.scanRegion = region; config.isTorchButtonVisible = false; config.isScanLaserVisible = false;
let config = BarcodeScannerConfig() config.isCloseButtonVisible = false let region = Rect() region.left = 0.15 region.top = 0.3 region.right = 0.85 region.bottom = 0.7 config.scanRegion = region config.isTorchButtonVisible = false config.isScanLaserVisible = false
Related APIs
Additional Settings
Auto Zoom Feature
Enable the camera to zoom-in automatically when:
- The barcodes are too small.
- The barcodes are farway from the camera.
Auto Zoom
- Objective-C
- Swift
DSBarcodeScannerConfig *config = [[DSBarcodeScannerConfig alloc] init]; config.isAutoZoomEnabled = true;
let config = BarcodeScannerConfig() config.isAutoZoomEnabled = true
Related API
Beep
Let the app to trigger a beep sound when a barcode is decoded.
- Objective-C
- Swift
DSBarcodeScannerConfig *config = [[DSBarcodeScannerConfig alloc] init]; config.isBeepEnabled = true;
let config = BarcodeScannerConfig() config.isBeepEnabled = true
Related API
Further Customization
If you have other customization requirements on the BarcodeScanner
component, you can modify it with the open source code on GitHub.