Skip to main content

Quick start | iOS Document Scanner

In this section, you'll learn how to set up the Scanbot Document Scanner SDK for iOS in your app, with Document Scanning enabled, all within 10 minutes – thanks to our Ready-to-Use UI!

Installing Scanbot SDK

Installation via Swift Package Manager

The Document Scanner SDK provides the ability to be integrated into your app via the Swift Package Manager (more about Swift Packages).

Installation guide

Step 1: Add the package Add Packages

Install additional OCR data bundle if needed (Swift Package Manager, ScanbotSDK only)

Step 1: Add a new target for the copy script Add New Target

  • Navigate to the project's settings and click the + button in the bottom left corner to add a new target.
  • In the target's template menu, navigate to Other, select Aggregate and click Next.
  • Name the new target, e.g. Copy Bundles, and click Finish.

Step 2: Add the copy script Add Script

  • Navigate to the newly created target's Build Phases, click the + button in the top left corner and select New Run Script Phase.
  • Copy this script to the editor:
cp -af "${BUILD_DIR%Build/*}/SourcePackages/checkouts/scanbot-sdk-ios-spm/Sources/AdditionalData/ScanbotSDKOCRData.bundle" "${PROJECT_DIR}/"
  • Navigate to the newly created target's Build Settings, find ENABLE_USER_SCRIPT_SANDBOXING and set it to NO. (Xcode 15 and later)
info

This script automatically copies additional bundles from the temporary package directory to your project's main directory.

Step 3: Add a dependency Add Dependency

  • Navigate to ScanbotSDK-Setup -> Build Phases and add the newly created target as a dependency.
  • Run the project.

Step 4: Add bundles to a Project Add Bundles to Xcode In the Finder, navigate to the project's folder and drag ScanbotSDKOCRData.bundle into Xcode, confirm ScanbotSDK-Setup target is checked and click Finish.

Add camera permission

To ensure your app is ready to use the ScanbotSDK, it's essential to request camera access by adding the NSCameraUsageDescription key to your Info.plist file. This step is necessary for the SDK to function properly, as it requires access to the device's camera for scanning documents.

Follow these steps to add the camera usage description:

  • Open your Info.plist file.
  • Click the + button and start typing Privacy - Camera Usage Description.
  • Provide a brief, user-friendly explanation of why your app needs camera access, such as: Please allow camera usage to scan documents.

For more details on requesting authorization to capture and save media, refer to the Apple documentation.

Initialize the SDK

In order to activate the license in the code use the +[Scanbot setLicense:] method of the Scanbot class. Execute this code as early as possible during your app's runtime, but at least before using any Scanbot SDK functionality, e.g. in your application class (AppDelegate).

If your license has expired, any invocation of the SDK's API will not work. You can check for license expiration during runtime by using the +[Scanbot isLicenseValid] method.

Example code for setting the license key string:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

Scanbot.setLicense(
"hiasVhl+q8EgpnDaCEjzDPgp6ex91j" +
"y6nLK60knb5DGnaMbxnx3pO7jrML5H" +
"5E6t1XGJ6tFsQm9mm+hSfVnetqEhe4" +
"VNfXzi/lFYpWT8ICQ1c7YbZbAeyPXc" +
"D/IcDaRz1vxS85aOL0tbYXynBzvkSx" +
"mMyFDaL/obrke4h+sonCbLauUA7yXX" +
"yWlT3gZujS6/a+SzhzpB+7+lCd+Y52" +
"GBvOsg+h8JfieM/oFzCUZrSazOEusU" +
"EyOewKLDiOdNqgJpAGK1hF1nQwhcr7" +
"PysYuECotHSE6NQ2vWJ6RqOz974prq" +
"EIjEhdprY62qD2pip2MbBHgKYL69DQ" +
"bFAgyNfSWNtg==\nU2NhbmJvdFNESw" +
"ppby5zY2FuYm90LmV4YW1wbGUuc2Rr" +
"LmRlbW8KMTU0NjM4NzE5OQo1MTIKMQ" +
"==\n")

return true
}

Start the Document Scanner and process the result

With just a few lines of code, the Scanbot Document Scanner Ready-To-Use UI component SBSDKUI2DocumentScannerController can be integrated into your application's workflow. It's as simple as starting any regular iOS View Controller.

// Create the default configuration object.
let configuration = SBSDKUI2DocumentScanningFlow()

// Present the recognizer view controller modally on this view controller.
SBSDKUI2DocumentScannerController.present(on: self,
configuration: configuration) { document in

// Completion handler to process the result.

if let document {
// Handle the document.

} else {
// Indicates that the cancel button was tapped.
}
}

🚀 That's it! 🚀 You have successfully integrated a full-featured document scanner as an RTU UI View Controller into your app.

💡 Customization: In this Quick Start guide, we use the default configuration for the scanner UI. Feel free to explore the configs and customize the UI and behavior according to your needs via the SBSDKUI2DocumentScanningFlow class. For more details, please refer to the Ready-to-Use UI page.

Want to scan longer than one minute?

Generate a free trial license to test the Scanbot SDK thoroughly.

Get your free Trial License

What do you think of this documentation?