I am working on integrating a dictation feature into a custom SwiftUI input field within an iOS app. My specific aim is to have a button adjacent to the input field that, when tapped, activates iOS’s built-in dictation so users can speak their input. While iOS automatically provides dictation for standard search bar inputs, there isn’t a straightforward method for implementing this for custom input fields. I found the TextInputDictationActivation in Apple’s documentation (link) but am unsure if it fits this particular use case or how to use it effectively for a custom input field.
I’ve explored the standard methods provided by SwiftUI for input fields but none directly support dictation initiation through an external button. After discovering the TextInputDictationActivation structure, I tried to implement it as suggested by the Apple documentation by embedding it into my input field’s view modifier. However, I’m not clear if I’m using it correctly as the documentation is sparse on examples. I expected to be able to trigger dictation similar to how it’s done automatically in a search bar, but instead, nothing happens when I interact with my setup. There’s no error, but also no action, which leaves me unsure if the issue is with my implementation or the approach itself.
Dmitry is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.