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

November 2, 2021

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

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:

Install the Scanbot SDK

You can integrate Scanbot SDK via Swift Package Manager, CocoaPods, Carthage, XCFramework 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:

Do a test run

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:

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:


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


class ViewController: UIViewController {

    @IBOutlet private var scannedDocumentImageView: UIImageView?

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

Adding the scanner


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

extension ViewController: SBSDKUIDocumentScannerViewControllerDelegate {
    func scanningViewController(_ viewController: SBSDKUIDocumentScannerViewController,
                                didFinishWith document: SBSDKUIDocument) {
    }
}

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 uiConfiguration, textConfiguration, and behaviorConfiguration of the SBSDKUIDocumentScannerConfiguration instance.


@IBAction func scanButtonDidTap(_ sender: UIButton) {
    if let scannerViewController = self.scannerViewController {
        self.present(scannerViewController, animated: true, completion: nil)
    }
}

    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 30-day trial license for free. 

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. 

Get the Scanbot SDK fact sheet

To access the fact sheet, Scanbot will process and use the information you provide to contact you about our products and to send you the monthly newsletter. You may unsubscribe from these communications at any time. For more information, please review our Privacy Policy.

Ready to try it?

Talk to one of our solutions experts to discover how we can solve your mobile data capture requirements or simply integrate it into your own mobile app or website right now.

Contact our solution experts
Try it

Developers, ready to get started?

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