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.
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:
<key>NSCameraUsageDescription</key>
<string>BKD Scanner requires using camera</string>
3. Add the scanner view #
Add BarkoderView as a view #
In your view controller, import BarkoderSDK, add a BarkoderView and lay it out:
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 #
(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:
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:
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:
try? barkoderView.startScanning(self)