Getting Started
This guide shows the minimal integration of Scan & Go into a SwiftUI app. SnabbleScanAndGo provides a complete, self-contained Scan & Go interface: barcode scanning, shopping cart, payment method selection and checkout are all handled by a single view, the ShopperView.
To integrate the SDK into your app you need an application identifier and a secret — contact us for access.
1. Configure Info.plist
The scanner needs access to the camera. Add a usage description to your app's Info.plist:
<key>NSCameraUsageDescription</key>
<string>The camera is used to scan product barcodes.</string>
If you want to sort shops by distance or check in automatically, also add NSLocationWhenInUseUsageDescription.
2. Set up the SDK and check in
Initialize the SDK with your credentials, load the product database and check the user into a shop. Checking in is essential: Scan & Go always operates in the context of a shop.
import SwiftUI
import SnabbleCore
import SnabbleComponents
@main
struct MyApp: App {
@State private var shop: Shop?
var body: some Scene {
WindowGroup {
Group {
if let shop {
ContentView(shop: shop)
} else {
ProgressView("Loading…")
}
}
.actionState()
.task {
setupSnabble()
}
}
}
@MainActor
private func setupSnabble() {
let config = Config(
appId: "YOUR_APP_ID",
secret: "YOUR_SECRET",
environment: .production
)
Snabble.setup(config: config) { snabble in
guard let project = snabble.projects.first else { return }
SnabbleCI.register(project)
snabble.setupProductDatabase(for: project) { _ in
Task { @MainActor in
if let firstShop = project.shops.first {
Snabble.shared.checkInManager.shop = firstShop
shop = firstShop
}
}
}
}
}
}
Apply .actionState() once at the root of your view hierarchy. This modifier connects the SDK to your UI so that toasts, dialogs, sheets and alerts triggered during a shopping session are displayed. Without it, these overlays are silently swallowed.
3. Present the ShopperView
Create a Shopper for the checked-in shop and present the ShopperView:
import SwiftUI
import SnabbleCore
import SnabbleScanAndGo
struct ContentView: View {
@State private var shopper: Shopper
@State private var showShopper = false
init(shop: Shop) {
_shopper = State(initialValue: Shopper(shop: shop))
}
var body: some View {
Button("Start Shopping", systemImage: "barcode.viewfinder") {
showShopper = true
}
.fullScreenCover(isPresented: $showShopper) {
ShopperView(model: shopper)
}
}
}
That's it. ShopperView covers the full shopping session:
- Barcode scanning with camera and manual entry
- Shopping cart management (quantities, deletion, promotions)
- Payment method selection and configuration
- Checkout with error handling
Configuration
The appearance of ShopperView can be adjusted with a ShopperConfiguration:
ShopperView(
model: shopper,
configuration: ShopperConfiguration(showDismiss: true)
)
| Parameter | Default | Description |
|---|---|---|
showDismiss | true | Shows a button to dismiss the ShopperView |
drawerOffset | 0 | Additional offset of the shopping cart drawer |
zoomControlOffset | 40 | Offset of the camera zoom control |
Next Steps
The SDK offers further modules that can be combined with Scan & Go:
- Shops (
SnabbleShops) – shop list and shop details including map and opening hours (ShopView) - Receipts (
SnabbleReceipts) – list and details of past purchases (PurchasesViewModel,ReceiptDetailScreen) - Payment (
SnabblePayment) – standalone management of payment methods (PaymentMethodListView) - Onboarding (
SnabbleOnboarding) – paged onboarding flow configured via JSON - Theming (
SnabbleAssetProviding) – custom colors, images and strings
All modules are documented in the API reference. A runnable version of this guide is available as MinimalScanAndGo sample app, a complete app as SwiftySnabble.