Speech-enable your WKWebView app

Dragon Copilot SDK for JavaScript supports iOS native applications that use WKWebView. This enables web-based speech and interaction features in a native app environment.

Platform-specific considerations

  • Use native iOS APIs to manage microphone and ambient recording permissions.

  • Your iOS app must manage authentication and transfer the token to the web app. The web app will then use this token to initialize the Dragon Copilot SDK.

    There are several ways to implement this, but we recommend WKScriptMessageHandlerWithReply. This approach enables JavaScript (from the web app) within a WKWebView to send a message to the native iOS code and receive an asynchronous reply using a promise in JavaScript.

Interruption handling

The Dragon Copilot SDK handles the following scenarios that commonly interrupt app usage on a mobile device:

Interruption Action during dictation Action during ambient recording
App goes to background Stop recording Customizable
Another app is opened Stop recording Customizable
Device is locked Stop recording Customizable
Incoming call Stop recording Stop recording

Customize interruption handling during ambient recording

To define the SDK behavior when an interruption occurs during ambient recording, use the continueAmbientRecordingDuringMobileInterruption property when you set the ambient session data.

  • false - recording stops when the app goes to the background, the screen locks, or other mobile interruptions occur. This is the default behavior.

  • true - recording continues if the app goes to the background or the screen locks, ensuring uninterrupted capture.

Incoming phone calls always stop ambient recording due to iOS limitations - WKWebView loses audio access.

const sessionData: AmbientSessionData = {
  correlationId: "encounter-123",
  continueAmbientRecordingDuringMobileInterruption: false // Enables interruption detection
};
dragon.recording.ambient.setSessionData(sessionData);