Documentation Index
Fetch the complete documentation index at: https://docs.go.gbgplc.com/llms.txt
Use this file to discover all available pages before exploring further.
General
What iOS versions does GBGBridge support?
iOS 15.0 and later. This covers all iPhone and iPad models that support iOS 15.Does GBGBridge have any external dependencies?
No. GBGBridge uses only Apple system frameworks: Foundation, WebKit, Combine, SwiftUI, and AVFoundation (forCameraDetector). It has zero third-party dependencies.
What Swift version is required?
Swift 5.9 or later. The framework is built withBUILD_LIBRARY_FOR_DISTRIBUTION enabled, which generates .swiftinterface files for binary module stability. This means you donât need to match the exact Swift compiler version used to build the framework.
How is GBGBridge distributed?
As an XCFramework via Swift Package Manager (SPM). The package contains a pre-built binary target that includes slices for both iOS device (arm64) and iOS Simulator (arm64 + x86_64).How large is the framework?
The GBGBridge binary is approximately 50 KB. It adds negligible size to your app.Integration
Can I use GBGBridge with UIKit?
Yes. UseBridgeWebViewConfigurator to configure a WKWebView in your UIKit view controller. See the Embedding Guide for details.
Can I use multiple BridgeHost instances?
EachBridgeHost should be associated with one WKWebView. If you have multiple WebViews (e.g., multiple journey tabs), create a separate BridgeHost for each.
Can I change capabilities after initialization?
With typed slots (init(hostVersion:)), capabilities are inherently dynamic. Set or clear handler to change support, toggle isEnabled to temporarily disable, and update permissionState as permissions change. The capability query response is built dynamically on each query.
With the configuration-based init, the capabilities dictionary is @Published and mutable, but the built-in CapabilityQueryHandler reads from a closure set at initialization. For fully dynamic capabilities in that path, replace the built-in handler with a custom one:
Do I need to handle the capability.query action myself?
No. BridgeHost automatically registers a CapabilityQueryHandler that responds to capability.query requests. With init(hostVersion:), it builds the response from typed slots and custom capabilities. With init(configuration:), it reads from the BridgeConfiguration.
What is the difference between typed slots and custom capabilities?
Typed slots (host.documentCapture, host.selfieCapture) are built-in CaptureCapability properties for well-known capture operations. They handle result encoding, busy rejection, and permission state automatically. Handlers return CaptureResult values.
Custom capabilities (registerCustomCapability()) support any action. Handlers receive a BridgeResponder and build responses manually using JSONValue dictionaries. Use this for non-camera capabilities like NFC.
Both appear in capability.query responses. If both are registered for the same ID, the typed slot takes precedence.
How does permission state work?
Each typed slot has apermissionState property (default: .notDetermined). Populate it using CameraDetector.check():
capability.query response as a permissionState field, allowing the web journey to detect permission issues before attempting capture.
What happens if the web journey sends a request for an action I havenât registered?
The request is added tohost.pendingRequests and bridgeHost(_:unhandledRequest:) is called on the delegate. You can respond to it manually via host.respond(to:status:data:error:).
If you donât respond, the request sits in pendingRequests indefinitely. The web journey may implement its own timeout.
Messaging
Are messages guaranteed to be delivered?
Messages sent via the bridge are in-process or inter-process calls through WebKit. They are delivered reliably as long as:- The WebView is attached to the host.
- The web page has not navigated away.
window.GBGBridge.receiveis defined on the web side.
What is the maximum message size?
There is no hard limit imposed by GBGBridge. However, very large messages (e.g., multi-megabyte Base64 images) can cause memory pressure. For large data transfers, consider passing file paths instead of inline data.Can I send messages before the web page loads?
Messages sent before the page loads (or before the web journey sets up itsreceive() function) will be lost. The default bootstrap script creates a no-op receive(), so the call wonât error â but the data wonât be processed.
Is the message order preserved?
Messages are processed in the order they arrive. Responses are sent in the orderrespond() is called. WebKitâs evaluateJavaScript calls are executed sequentially.
What happens to events â does anyone respond to them?
Events are fire-and-forget. They have no expected response. Both the native host and the web journey can send events. Use events for notifications, state updates, and lifecycle signals.Capabilities
How does the web journey know what capabilities are available?
The web journey sends acapability.query request. The built-in handler responds with the environment ("ios"), host version, and a map of all declared capabilities with their supported status, version, and optionally permissionState.
What if a capability is hardware-dependent?
For camera capabilities, useCameraDetector.check() and conditionally set the handler:
What NFC entitlements do I need?
To use NFC in your host app:- Add the Near Field Communication Tag Reading capability in Xcode.
- Include
com.apple.developer.nfc.readersession.formatsin your entitlements. - Add
NSNFCReaderUsageDescriptionto Info.plist.
CoreNFC APIs.
Security
Is communication between the host and web journey encrypted?
Communication uses WebKitâs internal IPC mechanism. It does not traverse the network, so TLS is not applicable. Messages are memory-to-memory within the device.Can other apps intercept bridge messages?
No. The WebView runs within your appâs sandbox. The script message handler channel is private to your app process.Should I validate incoming message data?
Yes. Treat data from the web journey the same way you would treat user input. Validate required fields, check value ranges, and reject malformed requests.Debugging
How do I see what messages are being exchanged?
Use theBridgeHostDelegate to log all messages:
host.$receivedMessages via Combine.
Can I use Safari Web Inspector?
Yes. Enable Web Inspector on your device (Settings â Safari â Advanced â Web Inspector), connect to a Mac, and inspect the WebView from Safariâs Develop menu. You can examinewindow.GBGBridge and test messages from the console.
Why do I see âWebView not attachedâ errors?
TheBridgeHost holds a weak reference to the WebView. If the WebView is deallocated, sending messages will produce this error. Ensure the WebViewâs lifetime matches or exceeds the hostâs lifetime.
Next Steps
- Getting Started â First integration walkthrough
- Troubleshooting â Detailed issue resolution
- API Reference â Complete type reference