Skip to content

barKoderSDK/ios-sdk

Repository files navigation

Installation Guide for barKoder's iOS Barcode Scanner SDK (v1.2.5)

Please follow these simple steps to integrate our SDK into your iOS project.

Create a new group

Name the group “frameworks”. The name is optional, you can use whichever label you want picture1.png

Add Barkoder.xcframework and BarkoderSDK.xcframework

Add these items into frameworks  (*Copy items if needed, Create groups and Add to desired targets) picture2.png

Enable Bitcode (set it to NO)

In Build Settings set the Enable Bitcode to NO like shown on the image picture3.png

Update Info.plist

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” picture4.png

Add BarkoderView as a view

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
    }
}

Licensing

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.

Create Barkoder Config

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
}

Implement BarkoderResultDelegate protocol

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)
    }
	}  
}

Start the scanning process

And finally start the scanning process:

try? barkoderView.startScanning(self)

How-to (best practices)

Enable DPM Mode

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)
    }

Set VIN

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)
    }

MultiScan

    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
    }

API reference for barKoder's iOS Barcode Scanner SDK

BarkoderView

Main Barkoder Class, the full list of API functions follows:

setPreviewFramesDelegate

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?)

setZoomFactor

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)

isFlashAvailable

Check if current mobile device has flash available

@objc public func isFlashAvailable(_ completion: @escaping(_ flashAvailable: Bool) ->
Void)

setFlash

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)

startCamera

Start the camera preview only, without decoding

@objc public func startCamera()

stopCamera

Stop the camera preview session and decoding if active

@objc func stopCamera()

resultDelegate

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

stopScanning

Stop the scanning process and the camera preview

@objc public func stopScanning()

pauseScanning

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

locationLineColor

Location line color as UIColor

@objc public var locationLineColor: UIColor

locationLineWidth

Get the location line width as float Default value is 2.0

@objc public var locationLineWidth: Float

roiLineColor

Region of interest line color as UIColor

@objc public var roiLineColor: UIColor

roiLineWidth

Region of interest line width as float Default value is 2.0

@objc public var roiLineWidth: Float

roiOverlayBackgroundColor

Region of interest background color as UIColor

@objc public var roiOverlayBackgroundColor: UIColor

closeSessionOnResultEnabled

Check if camera preview session will be closed when barcode is scanned Default value is true

@objc public var closeSessionOnResultEnabled: Bool

imageResultEnabled

Check if the image result is enabled Image result is received in BarkoderResultDelegate as UIImage Default value is false

@objc public var imageResultEnabled: Bool

locationInImageResultEnabled

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

locationInPreviewEnabled

Check if barcode location in preview is enabled Default value is true

@objc public var locationInPreviewEnabled: Bool

setRegionOfInterest

Set active region of interest

@objc open func setRegionOfInterest(_ value: CGRect) throws

getRegionOfInterest

Get active region of interest Default value is 'CGRect(x: 3, y: 30, width: 94, height: 40)'

@objc open func getRegionOfInterest() -> CGRect

setThreadsLimit

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

getThreadsLimit

Get maximum threads that are used for the decoding process

@objc open func getThreadsLimit() -> Int

pinchToZoomEnabled

Check if the camera preview can be zoomed with pinch Default value is false

@objc public var pinchToZoomEnabled: Bool

regionOfInterestVisible

Check if ROI is visible on the preview screen Default value is true

@objc public var regionOfInterestVisible: Bool

barkoderResolution

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

beepOnSuccessEnabled

Check if a device will beep on successful scan Default value is true

@objc public var beepOnSuccessEnabled: Bool

vibrateOnSuccessEnabled

Check if a device will vibrate on successful scan Default value is true

@objc public var vibrateOnSuccessEnabled: Bool

barcodeThumbnailOnResult

Getting barcode thumbnail on result

  • Default value is true
@objc public var barcodeThumbnailOnResult: Bool

thresholdBetweenDuplicatesScans

Getting threshold between duplicates scans

  • Default value is 5
@objc public var thresholdBetweenDuplicatesScans: Int

setMulticodeCachingEnabled

@objc open func setMulticodeCachingEnabled(_ boolean: Bool)

getMulticodeCachingEnabled

@objc open func getMulticodeCachingEnabled() -> Bool

setMulticodeCachingDuration

@objc open func setMulticodeCachingDuration(_ value: Int)

getMulticodeCachingDuration

@objc open func getMulticodeCachingDuration() -> Int

GetVersion

@objc public static func GetVersion() -> String

BarkoderHelper

scanImage

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)

applyConfigSettingsFromTemplate

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)

applyConfigSettingsFromURL

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)

applyConfigSettingsFromFile

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)

applyConfigSettingsFromJson

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)

barkoderConfig

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:

SwiftUI Human Interface Guidelines Swift and SwiftUI

About

The barKoder SDK for iOS grants an easy to use barcode scanning solution that can be integrated into the iOS mobile platform

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •