What this example demonstrates
- Typed capability slots for document capture with
CameraDetectorpermission state - Passport chip reading with the
host.nfcReadtyped 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: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:
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.
Graceful Degradation
Chip reading is detected at runtime withNFCTagReaderSession.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:- Add GBGBridge 1.2.0 or later via SPM.
- Add to Info.plist:
- For chip reading: Add the Near Field Communication Tag Reading capability.
- Update
journeyURLto your web journey endpoint. - Build and run.
Next steps
- Capability Handling Guide — Deep dive on capability patterns
- Security Guide — Production security checklist
- API Reference — Complete type reference