iOS 13 has voice dictation button in UISearchBar in all system applications, which duplicates mic button on system keyboard and shows dictation view:
But when I create new project in Xcode, add UISearchBar, and run application on device, it doesn't have mic button on UISearchBar.
Is there a way to make my application show that mic button on UISearchBar?
UISearchBar iOS 13 voice dictation button
Asked Answered
My phone is set to German language and locale settings and this button only shows up in the spotlight search (swipe down on homescreen). In all other system apps the search bar doesn't have this icon. So I'd also be interested in this behaviour and how we can enable it in our own apps. –
Crean
You can set the search bar book mark item to be visible and then change the image to be an image of the microphone. Then you can programmatically use the search bar delegate method "searchBarBookmarkButtonClicked" to set your action for clicking on the button. This will trigger UISpeech to listen and analyze the voice. Make sure you have the correct info.plist properties "Privacy - Microphone Usage Description" and "Privacy - Speech Recognition Usage Description" set to ask the user for permission.
let liveTextImage = UIImage(systemName: "text.viewfinder") searchController.searchBar.setImage(liveTextImage, for: .bookmark, state: []) searchController.searchBar.showsBookmarkButton = true
–
Tara There is a UISearchTextField instance in the UISearchBar. You can set the textField.rightView to a view of microphone. In the microphone button handler, you do the the speech-to-text recognition.
rightView has been broken on UISearchTextField for a long time.... answer from juliacas works –
Tara
© 2022 - 2024 — McMap. All rights reserved.