iOS Gallery scan

The SDK allows you to decode barcodes from image files. It supports several image formats, including BMP, PNG, and JPG. The config you pass must be made with your license key, BarkoderConfig(licenseKey:licenseCheckHandler:), as in the example below.

Swift
BarkoderHelper.scanImage(image, bkdConfig: bkdConfig, resultDelegate: self)

Here is an example of how you can access the photo library on your device and select and scan images from within the library:

Swift
extension ViewController: UIImagePickerControllerDelegate & UINavigationControllerDelegate {
   
  func presentImagePicker() {     
    let imagePicker = UIImagePickerController()
    imagePicker.delegate = self
    imagePicker.sourceType = .photoLibrary
    UINavigationBar.appearance().backgroundColor = .white
    UIBarButtonItem.appearance().tintColor = .black
    self.present(imagePicker, animated: true) {
      UINavigationBar.appearance().backgroundColor = .clear
      UIBarButtonItem.appearance().tintColor = .white
    }
  }

  func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
    picker.dismiss(animated: true, completion: nil)
     
    guard let image = info[.originalImage] as? UIImage else {
      return
    }
     
    // the license key is needed here too: a BarkoderConfig() without it has no decoder
    let bkdConfig = BarkoderConfig(licenseKey: "LICENSE_KEY") { licenseResult in
      print("Licensing SDK: \(licenseResult.message ?? "")")
    }

    BarkoderHelper.applyConfigSettingsFromTemplate(bkdConfig, template: .gallery_scan) { config in
      BarkoderHelper.scanImage(image, bkdConfig: config, resultDelegate: self)
    }
     
  }
   
  func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
    picker.dismiss(animated: true, completion: nil)
  }
   
}