Emoji Create quality document scans with our new simple-to-use demo app! Give it a try!

iOS development tutorial – how to add a document scanner into your iOS App

This article will show you how fast and easy it is to create an app with Scanbot SDK integrated. Let’s go…

Getting started

Requirements

  • macOS with the latest version of Xcode
  • iOS device running iOS 11 or later

Create an iOS app

Let’s start by creating a new iOS project.

For this tutorial, we will create a Swift project with the Storyboard interface.

To create an iOS project:

  •  in Xcode, go to File -> New -> Project…
  •  make sure you have the iOS tab selected, then choose App
  •  name it, e.g. MyAwesomeIOSApp
  •  choose Storyboard as the interface
  •  select Swift as the programming language.

Install the Scanbot SDK

You can integrate Scanbot SDK via Swift Package ManagerCocoaPodsCarthageXCFramework or download and add the Scanbot SDK package manually. In this tutorial, we’ll use Swift Package Manager.

To add the Scanbot SDK for iOS via Swift Package Manager:

  • in Xcode, go to File -> Swift Packages -> Add Package Dependency…
  • paste the Scanbot SDK for iOS URL – git@github.com:doo/scanbot-sdk-ios-spm.git – into the provided field.

Do a test run

  • adjust the Signing / Developer Account settings in Xcode
  • connect an iOS device 
  • run the app.

You should now see an empty screen.

Preparations

Before implementing any functionalities, we need to prepare our app for Scanbot SDK usage. Let’s start by adding support for using the camera API. To do that, you need to add the NSCameraUsageDescription to the Info.plist file:

  • go to the Info.plist file
  • press the + button and type “Privacy – Camera Usage Description” then briefly explain why you need access to the camera, e.g. “Camera access is required to scan documents”.

NOTE! If you do not have a trial license, skip the next step and use Scanbot SDK in trial mode. See also the license key notes at the end.

To add a Scanbot SDK trial license key:

  • open the AppDelegate file
  • add import ScanbotSDK to the top of the class
  • Set the trial license key in the function application(_: didFinishLaunchingWithOptions):
import UIKit
import ScanbotSDK

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

	func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
//        Uncomment this line if you have a license.
//        ScanbotSDK.setLicense("See the license key notes below!")
        return true
    }
}

Let’s Code!

Let’s start by building a UI for our project

  • in Main.storyboard, add a UIButton with the title “Scan Document” and a UIImageView for showing the scanned result
  • in the ViewController, define a variable scannedDocumentImageView and an action function scanButtonDidTap(_:):
class ViewController: UIViewController {

    @IBOutlet private var scannedDocumentImageView: UIImageView?

    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    @IBAction func scanButtonDidTap(_ sender: UIButton) {}
}

  • connect them to the UI components in the Main.storyboard:
iOS tutorial pic. 1
iOS Tutorial pic. 2

Adding the scanner

  • add import ScanbotSDK to the top of the ViewController
  • define a variable scannerViewController of type SBSDKUIDocumentScannerViewController inside the ViewController:
import ScanbotSDK

class ViewController: UIViewController, SBSDKUIDocumentScannerViewControllerDelegate {

    @IBOutlet private var scannedDocumentImageView: UIImageView?
    private var scannerViewController: SBSDKUIDocumentScannerViewController?

    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    @IBAction func scanButtonDidTap(_ sender: UIButton) {}
}

  • make ViewController conform to SBSDKUIDocumentScannerViewControllerDelegate by adding the following code:
extension ViewController: SBSDKUIDocumentScannerViewControllerDelegate {
    func scanningViewController(_ viewController: SBSDKUIDocumentScannerViewController,
                                didFinishWith document: SBSDKUIDocument) {
    }
}
  • to create an instance of SBSDKUIDocumentScannerViewController,  add these lines in the viewDidLoad() method:
override func viewDidLoad() {
    super.viewDidLoad()
    
    let configuration = SBSDKUIDocumentScannerConfiguration.default()
    self.scannerViewController = SBSDKUIDocumentScannerViewController.createNew(with: configuration, andDelegate: self)
}

NOTE! For this project, we’re using the default configuration (SBSDKUIDocumentScannerConfiguration.default()), but feel free to customize the UI, text, and behavior to your liking. Take a look at the config properties uiConfigurationtextConfiguration, and behaviorConfiguration of the SBSDKUIDocumentScannerConfiguration instance.

  • add presentation code to scanButtonDidTap(_:), which we created earlier:
@IBAction func scanButtonDidTap(_ sender: UIButton) {
    if let scannerViewController = self.scannerViewController {
        self.present(scannerViewController, animated: true, completion: nil)
    }
}

  • and finally, to show the scanned result, we need to override the scanningViewController(_:didFinishWith:) function of the SBSDKUIDocumentScannerViewControllerDelegate:
  func scanningViewController(_ viewController: SBSDKUIDocumentScannerViewController,
                                didFinishWith document: SBSDKUIDocument) {
        self.scannedDocumentImageView?.image = document.page(at: 0)?.documentImage()
    }

And that’s it. Build and run the project on a real device. You now should be able to start the Scanbot Document Scanner, scan a document, and display the resulting image.

Conclusion

Congratulations! You just built a fully functional Document Scanner with just a few lines of code. 

The Document Scanner component we just integrated here is a so-called Ready-to-Use UI (RTU UI) SDK component. The RTU-UI components included in the Scanbot SDK cover all common scanning use cases. They are also easy to integrate and customize. 

Besides the RTU-UI components, the Scanbot SDK provides Classic Components. These allow you to build a fully custom User Experience. For more details, please refer to our documentation.

You can download this example app here.

To see all the amazing features of the Scanbot SDK, download the full iOS Example. This project integrates all API functions, such as Cropping UI, Image Filtering, PDF and TIFF Rendering, Optical Character Recognition, Barcode and QR Code Scanning, MRZ Scanning (Machine Readable Zones), and EHIC Scanning (European Health Insurance Card).

Scanbot SDK (trial) license key

Please note: Without a license key, the Scanbot SDK will run for one minute per session! After the trial period is up, all Scanbot Scanner SDK functions as well as the UI components will stop working or may be terminated. 

Alternatively, you can get an unrestricted, no-strings-attached 7-day trial license for free. Or you can opt for a 30-day proof of concept.

As the Scanbot SDK license key is bound to a Bundle Identifier, you will have to use the default Bundle Identifier com.example.MyAwesomeIOSApp of this tutorial app. Alternatively, you can use the ID of your app when requesting your trial license. Please note that app IDs are case-sensitive!

Happy coding!

If you need any assistance, please feel free to contact one of our experts. We’d love to help you out. Let’s talk.

Developers, ready to get started?

Adding our free trial to your app is easy. Download the Scanbot SDK now and discover the power of mobile data capture.

Try it