Skip to main content
A production-style integration demonstrating custom configuration, lifecycle management, error handling, capability negotiation, and graceful degradation for environment-sensitive features like passport chip reading.

What this example demonstrates

  • Typed capability slots for document capture with CameraDetector permission state
  • Passport chip reading with the host.nfcRead typed slot (GBGBridge 1.2.0 or later)
  • Runtime capability detection with pre-launch validation
  • CaptureResult-based response encoding (no manual JSONValue dictionaries)
  • Lifecycle management (background/foreground events)
  • Delegate-based message observation and routing
  • Graceful degradation for unsupported capabilities

Complete source

The full app below is a single SwiftUI target that demonstrates pre-launch capability validation, typed slots for document capture and passport chip reading, lifecycle event forwarding, and delegate-based message observation. Read through the section markers (// MARK: -) to navigate; each block is the production-style version of a pattern shown elsewhere in the docs.

Architecture overview

Key patterns demonstrated

Pre-launch capability validation

Before starting the journey, the launcher checks whether all required capabilities are available:
This prevents users from starting a journey that will fail partway through due to missing hardware.

Lifecycle events

The app sends events when entering background and returning to foreground. The web journey can use these to pause/resume timers, save state, or handle session timeouts.

Permission state with CameraDetector

CameraDetector.check() detects hardware and permission status. The result is assigned to the typed slot’s permissionState, which is automatically included in capability query responses:
The web journey can now check permissionState before attempting capture and prompt the user to grant access if needed.

Typed Slots

This example uses a typed slot for each capability:
  • Document capture uses host.documentCapture. The SDK handles result encoding and busy rejection automatically.
  • Passport chip reading uses host.nfcRead. The handler waits for the reader sheet, and the SDK validates the request and builds the chip response. Don’t build that response yourself.
For capabilities without a typed slot, see Custom Capability Registration.

Graceful Degradation

Chip reading is detected at runtime with NFCTagReaderSession.readingAvailable. If it’s not available, the launcher shows a warning, and deviceCanRead makes the slot report document.nfc as unsupported. Chip reading has no web fallback, so the journey then asks the person to use a different device.

Running this example

To run the example end-to-end, follow these setup steps:
  1. Add GBGBridge 1.2.0 or later via SPM.
  2. Add to Info.plist:
  3. For chip reading: Add the Near Field Communication Tag Reading capability.
  4. Update journeyURL to your web journey endpoint.
  5. Build and run.

Next steps