Skip to main content
This example demonstrates bidirectional messaging between the native iOS host and the web journey: sending events to the web journey and handling incoming requests with capability handlers.

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)

The web journey receives this via window.GBGBridge.receive() and can use the timestamp and version information to initialize its state.

Incoming requests (web β†’ native)

When the web journey sends a camera.document.capture request, the typed slot handler runs:
The CaptureResult is automatically encoded to the bridge protocol format β€” no manual JSONValue dictionary construction needed.

Unhandled Requests

The MessageLogger 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

  1. Add GBGBridge to your project via SPM.
  2. Create a new SwiftUI App target.
  3. Replace the default ContentView with the code above.
  4. Update journeyURL to point to your web journey.
  5. Build and run.

Next Steps