What this example demonstrates
- Sending events from native to web
- Declaring capture support via typed capability slots
- Registering custom capabilities for non-camera actions
- Responding with success, error, and cancellation statuses
- Observing all bridge traffic via
BridgeHostDelegate
Complete source
Code explanation
The sections below cover what each part of the app does, in roughly the order they’re exercised at runtime.Outgoing events (native → web)
window.GBGBridge.receive() and can use the timestamp and version information to initialize its state.
Incoming requests (web → native)
When the web journey sends acamera.document.capture request, the typed slot handler runs:
CaptureResult is automatically encoded to the bridge protocol format — no manual JSONValue dictionary construction needed.
Unhandled Requests
TheMessageLogger delegate catches requests with no registered handler and responds with .unsupported. This prevents the web journey from waiting indefinitely for a response.
Running This Example
- Add GBGBridge to your project via SPM.
- Create a new SwiftUI App target.
- Replace the default
ContentViewwith the code above. - Update
journeyURLto point to your web journey. - Build and run.
Next Steps
- Advanced Integration — Lifecycle management, custom configuration, and capability checks
- Messaging Guide — Deep dive on message patterns