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(2)
barkoderView.config?.barkoderResolution = .high
// 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 normal
barkoderView.config?.decoderConfig?.decodingSpeed = DecodingSpeed.init(1)
barkoderView.config?.barkoderResolution = .normal
}
Find out more: