Please follow these simple steps to integrate our SDK into your iOS project.
Name the group “frameworks”. The name is optional, you can use whichever label you want
Add these items into frameworks  (*Copy items if needed, Create groups and Add to desired targets)
In Build Settings set the Enable Bitcode to NO like shown on the image
Open the Info.plist with Source Code and add these changes:
<key>NSCameraUsageDescription</key>
<string>BKD Scanner requires using camera</string>
Or using Property List add “Privacy - Camera Usage Description” and key "BKD Scanner requires using camera”
Import BarkoderSDK and delcare barkoderView as a view
import UIKit
import BarkoderSDK
class ViewController: UIViewController {
private var barkoderView: BarkoderView!
override func viewDidLoad() {
super.viewDidLoad()
setupUI()
setupConstraints()
}
private func setupUI() {
barkoderView = BarkoderView()
view.addSubview(barkoderView)
}
private func setupConstraints() {
barkoderView.translatesAutoresizingMaskIntoConstraints = false
barkoderView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
barkoderView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
barkoderView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
barkoderView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
}
}
The SDK will scan barcodes even without a license, however, certain characters will be marked with asterisks. To avoid this you can create a trial license or even a production license. Follow barkoder.com/register and create a trial license today.
Setup the Barkoder Config per your needs:
In order to perform scanning, config property needs to be properly set As mentioned, if the license key is not valid you will receive results with asterisks inside.
private func createBarkoderConfig() {
barkoderView.config = BarkoderConfig(licenseKey: "LICENSE_KEY") { licenseResult in print("Licensing SDK: \(licenseResult)") }
// Enable QR barcode type
guard let decoderConfig = barkoderView.config?.decoderConfig else { return }
decoderConfig.qr.enabled = true
}
To receive the scanned results we need to implement this protocol:
extension ViewController: BarkoderResultDelegate {
func scanningFinished(_ decoderResults: [DecoderResult], thumbnails: [UIImage]?, image: UIImage?) {
if let textualData = decoderResults[0].textualData {
print("Scanned result: ", textualData)
}
}
}
And finally start the scanning process:
try? barkoderView.startScanning(self)
Enabling via pre-defined template:
private func setDpmMode() {
// In order to perform scanning, config property need to be set before
// If license key is not valid you will receive results with asterisks inside
barkoderView.config = BarkoderConfig(licenseKey: "LICENSE_KEY") { licenseResult in
print("Licensing SDK: \(licenseResult)")
}
if let config = barkoderView.config {
BarkoderHelper.applyConfigSettingsFromTemplate(config, template: .dpm, finished: { updatedConfig in
// Enabling ROI
self.barkoderView.config?.regionOfInterestVisible = true
// Optional ROI for dpm mode if the viewfinder is on fullscreen
let dpmRoiRect = CGRect(x: 35, y: 40, width: 30, height: 14)
try? self.barkoderView.config?.setRegionOfInterest(dpmRoiRect)
})
}
}
Enabling it manually:
private func setDpmMode() {
// In order to perform scanning, config property need to be set before
// If license key is not valid you will receive results with asterisks inside
barkoderView.config = BarkoderConfig(licenseKey: "LICENSE_KEY") { licenseResult in
print("Licensing SDK: \(licenseResult)")
}
// Enabling datamatrix and dpm mode
barkoderView.config?.decoderConfig?.datamatrix.enabled = true
barkoderView.config?.decoderConfig?.datamatrix.dpmMode = 1
// For best result decoding speed should be slow, and barkoder resolution should be high
barkoderView.config?.decoderConfig?.decodingSpeed = DecodingSpeed.init(2)
barkoderView.config?.barkoderResolution = .high
// Setting ROI
let dpmRoiRect = CGRect(x: 35, y: 40, width: 30, height: 14)
try? self.barkoderView.config?.setRegionOfInterest(dpmRoiRect)
}
Seting it via pre-defined template:
private func setVin() {
// In order to perform scanning, config property need to be set before
// If license key is not valid you will receive results with asterisks inside
barkoderView.config = BarkoderConfig(licenseKey: "LICENSE_KEY") { licenseResult in
print("Licensing SDK: \(licenseResult)")
}
if let config = barkoderView.config {
BarkoderHelper.applyConfigSettingsFromTemplate(config, template: .vin, finished: { updatedConfig in
// Enabling ROI
self.barkoderView.config?.regionOfInterestVisible = true
// Optional ROI for vin if the viewfinder is on fullscreen
let vinRoiRect = CGRect(x: 0, y: 35, width: 100, height: 30)
try? self.barkoderView.config?.setRegionOfInterest(vinRoiRect)
})
}
}
Setting it manually:
private func setVin() {
// In order to perform scanning, config property need to be set before
// If license key is not valid you will receive results with asterisks inside
barkoderView.config = BarkoderConfig(licenseKey: "LICENSE_KEY") { licenseResult in
print("Licensing SDK: \(licenseResult)")
}
// Enabling code39, code128, datamatrix and qr
barkoderView.config?.decoderConfig?.code39.enabled = true
barkoderView.config?.decoderConfig?.code128.enabled = true
barkoderView.config?.decoderConfig?.datamatrix.enabled = true
barkoderView.config?.decoderConfig?.qr.enabled = true
// For best result decoding speed should be slow, and barkoder resolution should be high
barkoderView.config?.decoderConfig?.decodingSpeed = DecodingSpeed.init(1)
barkoderView.config?.barkoderResolution = .normal
// Setting ROI
let vinRoiRect = CGRect(x: 0, y: 35, width: 100, height: 30)
try? self.barkoderView.config?.setRegionOfInterest(vinRoiRect)
}
private func setMultiScan() {
// In order to perform scanning, config property need to be set before
// If license key is not valid you will receive results with asterisks inside
barkoderView.config = BarkoderConfig(licenseKey: "LICENSE_KEY") { licenseResult in
print("Licensing SDK: \(licenseResult)")
}
// Enabling MultiScan
barkoderView.config?.closeSessionOnResultEnabled = false
barkoderView.config?.setMulticodeCachingDuration(3000)
barkoderView.config?.setMulticodeCachingEnabled(true)
barkoderView.config?.decoderConfig?.duplicatesDelayMs = 0
barkoderView.config?.decoderConfig?.maximumResultsCount = 200
// For best result decoding speed should be normal, and barkoder resolution should be high
barkoderView.config?.decoderConfig?.decodingSpeed = DecodingSpeed.init(1)
barkoderView.config?.barkoderResolution = .high
}
Main Barkoder Class, the full list of API functions follows:
Set camera frames callback if you want to receive the frames/images only without decoding them and do your own work with the frames
@objc public func setPreviewFramesDelegate(_ delegate:
BarkoderPreviewFramesDelegate?)
Set zoom factor for the camera preview If a preview session is already active this zoom factor will be set only for this session, therefore initial zoom will be set every next preview session is started with this zoom factor
@objc public func setZoomFactor(_ zoomFactor: Float)
Check if current mobile device has flash available
@objc public func isFlashAvailable(_ completion: @escaping(_ flashAvailable: Bool) ->
Void)
Turn flash ON/OFF
If preview session is already active this state will be set only for active session otherwise the initial flash state is set. Every next preview session will be started with this state
- Parameter enabled: [true, false]. Default value is false
@objc public func setFlash(_ enabled: Bool)
Start the camera preview only, without decoding
@objc public func startCamera()
Stop the camera preview session and decoding if active
@objc func stopCamera()
Start the camera preview (if is not already running) and the scanning process
- Parameter resultDelegate
- Throws Error if BarkoderView config is not set
@objc public func startScanning(_ resultDelegate: BarkoderResultDelegate) throws
Stop the scanning process and the camera preview
@objc public func stopScanning()
Pause only the scanning process. Camera preview is still running
@objc public func pauseScanning()
Get the decoder config object. With this object you can enable/disable decoders (barcode types) or configure each one of them
@objc public var decoderConfig: Config? = nil
Location line color as UIColor
@objc public var locationLineColor: UIColor
Get the location line width as float Default value is 2.0
@objc public var locationLineWidth: Float
Region of interest line color as UIColor
@objc public var roiLineColor: UIColor
Region of interest line width as float Default value is 2.0
@objc public var roiLineWidth: Float
Region of interest background color as UIColor
@objc public var roiOverlayBackgroundColor: UIColor
Check if camera preview session will be closed when barcode is scanned Default value is true
@objc public var closeSessionOnResultEnabled: Bool
Check if the image result is enabled Image result is received in BarkoderResultDelegate as UIImage Default value is false
@objc public var imageResultEnabled: Bool
Check if barcode location in the image result is enabled If enabled, barcode in the result image will be marked Default value is false
@objc public var locationInImageResultEnabled: Bool
Check if barcode location in preview is enabled Default value is true
@objc public var locationInPreviewEnabled: Bool
Set active region of interest
@objc open func setRegionOfInterest(_ value: CGRect) throws
Get active region of interest Default value is 'CGRect(x: 3, y: 30, width: 94, height: 40)'
@objc open func getRegionOfInterest() -> CGRect
Set maximum threads that will be used for the decoding process
- Parameter value: [1, max threads available]
- Throws Error if input param is greater than maximum threads available on that device
@objc func setThreadsLimit(_ value: Int) throws
Get maximum threads that are used for the decoding process
@objc open func getThreadsLimit() -> Int
Check if the camera preview can be zoomed with pinch Default value is false
@objc public var pinchToZoomEnabled: Bool
Check if ROI is visible on the preview screen Default value is true
@objc public var regionOfInterestVisible: Bool
Get the active resolution. It can be Normal(HD), or HIGH(Full HD) Default value is BarkoderView.BarkoderResolution.normal
@objc public var barkoderResolution: BarkoderView.BarkoderResolution
Check if a device will beep on successful scan Default value is true
@objc public var beepOnSuccessEnabled: Bool
Check if a device will vibrate on successful scan Default value is true
@objc public var vibrateOnSuccessEnabled: Bool
Getting barcode thumbnail on result
- Default value is true
@objc public var barcodeThumbnailOnResult: Bool
Getting threshold between duplicates scans
- Default value is 5
@objc public var thresholdBetweenDuplicatesScans: Int
@objc open func setMulticodeCachingEnabled(_ boolean: Bool)
@objc open func getMulticodeCachingEnabled() -> Bool
@objc open func setMulticodeCachingDuration(_ value: Int)
@objc open func getMulticodeCachingDuration() -> Int
@objc public static func GetVersion() -> String
Scan barcode from a bitmap image Parameters:
- image: Image that you want to be scanned as UIImage
- bkdConfig: config that will be used for scanning process
- resultDelegate: where you will receive scanned result
@objc public static func scanImage(_ image: UIImage, bkdConfig: BarkoderConfig,resultDelegate: BarkoderResultDelegate)
Apply config params from a pre-defined template Parameters:
- config: that will be configured
- template: that will be applied on config
- finished: that will be executed when this function is finished
@objc public static func applyConfigSettingsFromTemplate(_ config: BarkoderConfig,
template: BarkoderConfigTemplate, finished: @escaping (BarkoderConfig) -> Void)
Retrieve config properties from the URL and apply them in the config that is sent as an input param Parameters:
- config: that will be configured
- url: URL to the JSON file
- finished: callback that will be executed when this function is finished
@objc public static func applyConfigSettingsFromURL(_ config: BarkoderConfig, url: URL,
finished: @escaping (BarkoderConfig?, Error?) -> Void)
Retrieve config properties from the URL and apply them in the config that is sent as an input param Parameters:
- config: that will be configured
- url: filePath to the JSON file
- finished: callback that will be executed when this function is finished
@objc public static func applyConfigSettingsFromFile(_ config: BarkoderConfig, url: String,
finished: @escaping (BarkoderConfig?, Error?) -> Void)
Parameters:
- config: that will be configured
- jsonData: JSON
- finished: callback that will be executed when this function is finished
@objc public static func applyConfigSettingsFromJson(_ config: BarkoderSDK.BarkoderConfig, jsonData: Data, finished: @escaping (BarkoderSDK.BarkoderConfig?, (Error)?) -> Void)
Export config that is send as input param to JSON string
- Parameter barkoderConfig: config that will be exported
- Returns: JSON string
@objc public static func configToJSON(_ barkoderConfig: BarkoderConfig) -> String?
Find out more: