Detecting host app bundle ID from keyboard extension to enable "return to app" after deep link

I'm building a voice-to-text keyboard extension that needs to open the main app briefly for audio recording (since keyboard extensions can't record audio), then return the user to their original app.

The flow I'm trying to achieve:

  1. User is in WhatsApp (or Messages, Slack, etc.)
  2. User taps "Voice" button in my keyboard
  3. My main app opens via deep link (myapp://keyboard/dictation)
  4. App starts recording
  5. App automatically returns user to WhatsApp

I cannot find a way to detect which app the keyboard is running inside, or which app opened my main app via the deep link.

  1. UIInputViewController.textDocumentProxy - No host app information available

  2. UIApplication.OpenURLOptionsKey.sourceApplication in application(_:open:options:) - When opened from a keyboard extension, does this return the host app bundle ID or the keyboard extension bundle ID?

  3. Private APIs (for research only, not production):

    • _hostBundleID on UIInputViewController - blocked/returns nil on iOS 18
    • KVC approaches - all blocked
  4. Hardcoded app support - Works but requires maintaining a list of popular apps and showing multiple buttons instead of a single "Voice" button

My questions:

  1. When a keyboard extension triggers a URL open (via SwiftUI Link or UIApplication.shared.open), what does sourceApplication contain? The host app or the keyboard extension?

  2. Is there any supported way for a main app to know which app it was launched from, specifically when that launch originated from a keyboard extension?

  3. How do apps like "Wispr Flow" achieve seamless return-to-app with a single voice button? They seem to auto-return to whatever app the user was in.

Environment:

  • iOS 18.0+
  • Xcode 16
  • SwiftUI keyboard using KeyboardKit

Any guidance on the recommended approach would be greatly appreciated. I understand there may be privacy reasons for limiting host app detection, but the UX of requiring users to manually swipe back (or tap app-specific buttons) is significantly worse than automatic return.

Detecting host app bundle ID from keyboard extension to enable "return to app" after deep link
 
 
Q