In this tutorial, we’ll use Xcode, Swift, and the Scanbot VIN Scanner SDK to create an iOS app for extracting Vehicle Identification Numbers from a live camera stream.

We’ll achieve this in just four easy steps:
- Preparing the project
- Setting up the main screen
- Implementing the VIN scanning feature
All you need is a Mac with the latest version of Xcode and a test device, since we’ll need to use the camera.
Want to see the final code right away? Click here.
ViewController.swift:
import UIKit
import ScanbotSDK
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func scanVinButtonTapped(_ sender: Any) {
let configuration = SBSDKUI2VINScannerScreenConfiguration()
configuration.scannerConfiguration.extractVINFromBarcode = true
SBSDKUI2VINScannerViewController.present(on: self,
configuration: configuration) { result in
if let result {
var message = ""
if !result.textResult.rawText.isEmpty {
message = result.textResult.rawText
} else if !result.barcodeResult.extractedVIN.isEmpty {
message = result.barcodeResult.extractedVIN
} else {
message = "No VIN found."
}
let alert = UIAlertController(title: "Result",
message: message,
preferredStyle: .alert)
let action = UIAlertAction(title: "OK",
style: .cancel)
alert.addAction(action)
self.present(alert, animated: true)
} else {
let alert = UIAlertController(
title: "No Result",
message: "Scanning process canceled by the user.",
preferredStyle: .alert
)
let action = UIAlertAction(title: "OK", style: .cancel)
alert.addAction(action)
self.present(alert, animated: true)
}
}
}
}
Step 1: Prepare the project
Open Xcode and create a new iOS App project. Name the project (e.g., “iOS VIN Scanner”), choose Storyboard as the interface, and Swift as the language.
After opening your project, go to File > Add Package Dependencies… and add the Scanbot SDK package for the Swift Package Manager.
Open your Main App Target’s Info tab and add a Privacy – Camera Usage Description key with a value such as “Grant camera access to start scanning”.
In AppDelegate.swift, add a line for setting the license key to the application(_:didFinishLaunchingWithOptions:)
method. We don’t need one for this tutorial, but if you have a license key you’d like to use, uncomment the code below and replace <YOUR_LICENSE_KEY>
with your actual key.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Uncomment the following line and replace <YOUR_LICENSE_KEY> with your actual key
// Scanbot.setLicense("<YOUR_LICENSE_KEY>")
return true
}
Without a license key, the SDK will run in trial mode for 60 seconds per session. If you need more than that, you can generate a free trial license.
Step 2: Set up the main screen
We’ll now create a simple UI for starting our VIN Scanner.
First, open Main.storyboard and add a UIButton with a meaningful label (e.g., “Scan VIN”) to the main view.
After that, create an IBAction for the button in ViewController.swift and implement the button action to present the scanner view controller.
@IBAction func scanVinButtonTapped(_ sender: UIButton) {
// Code to present the scanner view controller will go here
}
We’ll also need to add the following import to ViewController.swift:
import ScanbotSDK
Step 3: Implement the VIN scanning feature
This step involves presenting the VIN Scanner view controller. The Scanbot SDK provides a pre-built UI for the scanning process.
Add the following code inside scanVinButtonTapped()
in ViewController.swift:
@IBAction func scanVinButtonTapped(_ sender: Any) {
// Create the default configuration object.
let configuration = SBSDKUI2VINScannerScreenConfiguration()
// Present the view controller modally.
SBSDKUI2VINScannerViewController.present(on: self,
configuration: configuration) { result in
if let result {
var message = result.textResult.rawText
let alert = UIAlertController(title: "Result",
message: message,
preferredStyle: .alert)
let action = UIAlertAction(title: "OK",
style: .cancel)
alert.addAction(action)
self.present(alert, animated: true)
} else {
// Indicates that the cancel button was tapped.
}
}
You can also handle the user canceling the scanning process like this:
} else {
let alert = UIAlertController(
title: "No Result",
message: "Scanning process canceled by the user.",
preferredStyle: .alert
)
let action = UIAlertAction(title: "OK", style: .cancel)
alert.addAction(action)
self.present(alert, animated: true)
}
Your ViewController.swift will then look like this:
import UIKit
import ScanbotSDK
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func scanVinButtonTapped(_ sender: Any) {
let configuration = SBSDKUI2VINScannerScreenConfiguration()
SBSDKUI2VINScannerViewController.present(on: self,
configuration: configuration) { result in
if let result {
var message = result.textResult.rawText
let alert = UIAlertController(title: "Result",
message: message,
preferredStyle: .alert)
let action = UIAlertAction(title: "OK",
style: .cancel)
alert.addAction(action)
self.present(alert, animated: true)
} else {
let alert = UIAlertController(
title: "No Result",
message: "Scanning process canceled by the user.",
preferredStyle: .alert
)
let action = UIAlertAction(title: "OK", style: .cancel)
alert.addAction(action)
self.present(alert, animated: true)
}
}
}
}
Our iOS VIN Scanner is now ready. Build and run the app and scan a Vehicle Identification Number …

… to test your scanner!

Optional: Enable VIN barcode scanning
VINs often come with a barcode encoding the same character sequence. You can enable barcode scanning in addition to regular VIN extraction to make your app even more reliable.
To do that, first adapt the scanner configuration in ViewController.swift:
@IBAction func scanVinButtonTapped(_ sender: Any) {
let configuration = SBSDKUI2VINScannerScreenConfiguration()
// Enable VIN barcode scanning
configuration.scannerConfiguration.extractVINFromBarcode = true
SBSDKUI2VINScannerViewController.present(on: self,
configuration: configuration) { result in
if let result {
//...
Then change the logic so that the scanning result is displayed to the user no matter if the scanner first picks up the character sequence or the barcode:
SBSDKUI2VINScannerViewController.present(on: self,
configuration: configuration) { result in
if let result {
var message = ""
if !result.textResult.rawText.isEmpty {
// If the VIN number is scanned first
message = result.textResult.rawText
} else if !result.barcodeResult.extractedVIN.isEmpty {
// If the VIN barcode is scanned first
message = result.barcodeResult.extractedVIN
} else {
// If neither the VIN number nor barcode can be scanned
message = "No VIN found."
}
let alert = UIAlertController(title: "Result",
message: message,
preferredStyle: .alert)
let action = UIAlertAction(title: "OK",
style: .cancel)
alert.addAction(action)
self.present(alert, animated: true)
} else {
let alert = UIAlertController(
title: "No Result",
message: "Scanning process canceled by the user.",
preferredStyle: .alert
)
let action = UIAlertAction(title: "OK", style: .cancel)
alert.addAction(action)
self.present(alert, animated: true)
}
}
Conclusion
This completes the basic implementation of a VIN Scanner for iOS using Swift and the Scanbot SDK. We used the SDK’s Ready-to-Use UI Components for this tutorial, but you can further customize the VIN scanning screen to fit your needs.
Should you have questions or run into any issues, we’re happy to help! Just shoot us an email via tutorial-support@scanbot.io.
Happy scanning! 🤳