On this page

Stuck? Open a support ticket and the barKoder team will help. Open a ticket

iOS Installation

1. Add the package #

Create a new group #

In Xcode, add a group to your project for the SDK, for example frameworks.

Add Barkoder.xcframework and BarkoderSDK.xcframework #

Download the iOS SDK package from Downloads in the barKoder Developer Portal and unzip it: its framework folder holds both. Add these items to the frameworks group (Copy items if needed, Create groups and Add to desired targets). Both are dynamic frameworks: in your target's General tab, under Frameworks, Libraries, and Embedded Content, make sure both are set to Embed & Sign. To install with Swift Package Manager instead, see Install via SPM.

Image 1 - Target, General: both frameworks set to Embed & Sign
Image 1 - Target, General: both frameworks set to Embed & Sign

Enable Bitcode (older Xcode only) #

Older Xcode versions (13 and earlier) required Enable Bitcode set to NO in Build Settings. Xcode 14 and later have bitcode deprecated and off, so there is nothing to change.

2. Allow the camera #

Update Info.plist #

The scanner needs the camera. Open Info.plist as source code and add the camera key:

XML-DOC
<key>NSCameraUsageDescription</key>
<string>BKD Scanner requires using camera</string>
Or, in your target's Info tab, add the key “Privacy - Camera Usage Description” with the value “BKD Scanner requires using camera”, as in Image 2.
Image 2 - Target, Info: Privacy - Camera Usage Description
Image 2 - Target, Info: Privacy - Camera Usage Description

3. Add the scanner view #

Add BarkoderView as a view #

In your view controller, import BarkoderSDK, add a BarkoderView and lay it out:

Swift
import UIKit
import BarkoderSDK
class ViewController: UIViewController {
    private var barkoderView: BarkoderView!
    override func viewDidLoad() {
        super.viewDidLoad()
        setupUI()
        setupConstraints()
        createBarkoderConfig()
    }
    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
    }
}

4. Set the license key and barcode types #

Licensing #

Without a valid license key the SDK still scans, but each result starts with (Unlicensed) and part of its data is replaced with dots. Get a free trial key on the trial page: choose Native or WASM and enter your app ID (for the Web SDK, your domain). A trial key lasts 30 days, for up to 25 devices, one per app ID. For a production license, request a quote. By using the SDK you agree to the End User License Agreement.

Create barKoder Config #

Add this method to your ViewController (viewDidLoad above calls it). It sets your license key and turns on the barcode types you scan; scanning needs the config set first:

Swift
private func createBarkoderConfig() {
    barkoderView.config = BarkoderConfig(licenseKey: "LICENSE_KEY") { licenseResult in print("Licensing SDK: \(licenseResult.message ?? "")") }

    // Enable QR barcode type
    guard let decoderConfig = barkoderView.config?.decoderConfig else { return }
    decoderConfig.qr.enabled = true
}

5. Start scanning and read results #

Implement BarkoderResultDelegate protocol #

Each result comes to BarkoderResultDelegate:

Swift
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 #

Start scanning, for example in viewDidAppear or when the user taps a Scan button:

Swift
try? barkoderView.startScanning(self)