I am currently faced with a problem related to UISearchBar
and dictation support. I have to call some filter logic when the text of the search bar changes. This logic must be triggered either by a change that was made using the keyboard or dictation.
Now here is my problem: if I end the dictation in the search bar, the textDidChange
method starts immediately (while speech recognition is in textDidChange
). After recognition, the method starts again with the correct line.
How to determine that the first method call was initiated by the beginning of speech recognition? Because I have to avoid doing my logic in this case.
I already tried to check the searchText
parameter, which is passed to the method. But the results are seemingly suspicious.
If I add this code to searchBar:textDidChange:
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText { NSLog(@"SearchText [%@] - SearchTextLength [%i] - SearchTextEquals [%i]", searchText, searchText.length, [searchText isEqualToString:@""]); }
I get this result:
SearchText [๏ฟผ] - SearchTextLength [1] - SearchTextEquals [0]
I am stuck at this point. How can searchText
be [] (empty) but has a length of 1? Is there any other way to detect that speech recognition still works?
source share