What this example demonstrates
- Typed capability slots for document capture with
CameraDetectorpermission state - Custom capability registration for NFC
- 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, custom NFC capability registration, 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 vs Custom Capabilities
This example demonstrates both patterns side by side:- Document capture uses a typed slot (
host.documentCapture) — the SDK handles result encoding and busy rejection automatically. - NFC uses
registerCustomCapability()— the handler receives aBridgeResponderand builds the response manually.
Graceful Degradation
NFC is detected at runtime. If not available, the launcher shows a warning, and the custom capability handler responds with.unsupported if somehow called.
Running this example
To run the example end-to-end, follow these setup steps:- Add GBGBridge via SPM.
- Add to Info.plist:
- For NFC: 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