RORK LABJP
TEST — The Rork Companion app lets you test on a real iPhone without a paid Apple Developer accountCLOUD — Code compiles on a cloud Mac, streaming a 60fps live simulator with real touch inputBROWSER — Design, code, and test entirely in Chrome or Safari — no Xcode requiredPUBLISH — Two-click App Store publishing keeps the submission process simpleMAX — Rork Max builds native Swift apps for iPhone, iPad, Apple Watch, and Vision ProRN — Standard Rork generates iOS and Android apps together with React Native (Expo)TEST — The Rork Companion app lets you test on a real iPhone without a paid Apple Developer accountCLOUD — Code compiles on a cloud Mac, streaming a 60fps live simulator with real touch inputBROWSER — Design, code, and test entirely in Chrome or Safari — no Xcode requiredPUBLISH — Two-click App Store publishing keeps the submission process simpleMAX — Rork Max builds native Swift apps for iPhone, iPad, Apple Watch, and Vision ProRN — Standard Rork generates iOS and Android apps together with React Native (Expo)
Articles/App Dev
App Dev/2026-06-28Advanced

Building a Live Barcode and Text Scanner in Rork Max with VisionKit's DataScanner

Add a live barcode and text scanner to your Rork Max native Swift app using VisionKit's DataScanner. Covers the SwiftUI bridge, availability handling, throttling repeated detections, and on-device verification with working code.

Rork Max189VisionKitSwiftUI55DataScanneriOS85App Development32

Premium Article

When I asked Rork Max to extend a generated native Swift screen with "let me scan a product barcode," the browser live simulator showed an empty frame and the camera never opened. After some digging the answer was simple: VisionKit's DataScannerViewController does not run in the simulator at all. It only starts on a supported physical device. Rork has been smoothing out real-device testing through its Companion app and cloud Mac compilation in 2026, and camera-dependent features like this are exactly the kind you should plan to verify on hardware from the very start.

This walkthrough adds a screen that recognizes barcodes and text live, at the same time, to your Rork Max native Swift code — including the SwiftUI bridge and on-device verification. As an indie developer who has shipped apps to the App Store since 2014, I have learned that camera features trip you up most often on two fronts: permissions and device differences. I will call those out as we go.

Why pick DataScanner over hand-rolled AVFoundation

There are two common ways to read codes from the camera on iOS. The classic route is wiring up AVCaptureSession yourself and pulling barcodes from AVCaptureMetadataOutput. The other is VisionKit's DataScannerViewController, introduced in iOS 16, which bundles the camera preview, subject highlighting, pinch-to-zoom, and guidance UI together.

AspectHand-rolled AVFoundationVisionKit DataScanner
Preview renderingPlace AVCaptureVideoPreviewLayer yourselfBuilt in
Text recognitionCombine with Vision separatelySame API as barcodes, captured together
HighlightingDraw rectangles manuallyStandard via isHighlightingEnabled
Device supportWorks broadly with any cameraA12 Bionic and later (Neural Engine) only
SimulatorSometimes works, limitedUnsupported (real device required)

For cases where you want to read a product code and a model-number string together, DataScanner is dramatically shorter to write. The trade-off is the limited device support and the simulator gap, both of which you need to design around from the beginning. Before I write a line of scanner code, I decide what to show when scanning is not available.

Step 1: Declare the permission and request camera access

First, add NSCameraUsageDescription to Info.plist. You can edit it from the Rork Max project settings too. A specific, purpose-driven string removes one common App Store review rejection reason.

<key>NSCameraUsageDescription</key>
<string>Used to scan product barcodes and model numbers with the camera.</string>

Request access explicitly before showing the screen. DataScannerViewController.isAvailable returns false when the camera is not authorized, so if you check availability without first prompting, you will misclassify a perfectly capable device as "unsupported." That was my first stumble.

import AVFoundation
 
func requestCameraAccess() async -> Bool {
    switch AVCaptureDevice.authorizationStatus(for: .video) {
    case .authorized:
        return true
    case .notDetermined:
        // The dialog appears here on first run. Call this BEFORE checking availability.
        return await AVCaptureDevice.requestAccess(for: .video)
    case .denied, .restricted:
        return false
    @unknown default:
        return false
    }
}

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
Turn a scanner feature that silently failed in the simulator into one that reliably runs on real devices, with a proper availability gate
Get a UIViewControllerRepresentable wrapper that bridges DataScannerViewController into SwiftUI, plus a 1.5-second throttle that stops the same code from firing over and over
Assemble a screen that recognizes barcodes and text at the same time, from the permission prompt to the result display
Secure payment via Stripe · Cancel anytime

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Rork Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • Copy-paste ready implementation code
  • New advanced guides published daily
  • $5/mo or $10 for lifetime access
View Membership →

Related Articles

App Dev2026-06-16
Staging Wallpaper Packs Before the First Launch: Where Rork Max and Background Assets Fit
Content-heavy apps tend to greet new users with an empty grid. Background Assets downloads content out-of-band, ahead of the first launch. Here is how I implement it in Rork Max's native Swift, a domain Rork (Expo) cannot reach easily, plus how I decide when it is worth it.
App Dev2026-06-16
Building a WeatherKit App with Rork Max — The Auth and Attribution Pitfalls
When you add WeatherKit to a native Swift app generated by Rork Max, the first walls are authentication and attribution. Here is the workflow I confirmed: token handling, rate limits, and the mandatory data-source display.
App Dev2026-06-14
Designing WidgetKit Timelines Around the Refresh Budget: Why My Wallpaper Widgets Stopped
Why does a home screen widget stop updating after the evening? A clear look at WidgetKit timeline design through three lenses: the refresh budget, the reload policy, and entry density. With a working TimelineProvider, an entry design that does not burn through the budget, and relevance-based prioritization, drawn from running six wallpaper apps solo.
📚RECOMMENDED BOOKS
Build a Large Language Model (From Scratch)
Sebastian Raschka
LLM Dev
Prompt Engineering for LLMs
Berryman & Ziegler
Prompting
AI Engineering
Chip Huyen
AI Eng
* Contains affiliate links
See all →