Problem:
I have UITextField
side by side with UIButton
with send functionality. When user presses send button I'm performing simple action:
- (IBAction)sendMessage: (id)sender {
[self.chatService sendMessage: self.messageTextField.text];
self.messageTextField.text = @""; // here I get exception
}
Now when user starts using dictation from keyboard, then presses done on dictation view (keyboard) and immediately presses send button, I've got exception "Range or index out of bounds".
Possible solution:
I've noticed that other applications disable this "send" button when speech recognition server is processing data. This is exactly between two events: user presses "done" and results are appearing in text field. I wish to solve it in the same manner.
I've problem finding in documentation where this notification can be received. I've found UITextInput
protocol, but this is not what I need.
Similar topics:
- Using Dictation - iOS 6 - DidStart - solution not acceptable (might be rejected by apple)
- Disable Dictation button on the keyboard of iPhone 4S / new iPad - similar approach as above
What have I tried:
- simply catch and ignore exception. Crash didn't acured, but virtual keyboard become completely unresponsive
- Disabling send button when
[UITextInputMode currentInputMode].primaryLanguage
is equal@"dictation"
. NotificationUITextInputCurrentInputModeDidChangeNotification
which reports end of dictation mode arrives before dictation service commits new value and I'm still able to click send button to cause exception. I could add delay whenprimaryLanguage
losses @"dictation" value, but I don't like this approach. Most probably this required delay depends how much speech recognition service is responsive. - I've added bunch of actions on different events (this evets was looking processing:
UIControlEventEditingDidBegin
,UIControlEventEditingChanged
,UIControlEventEditingDidEnd
,UIControlEventEditingDidEndOnExit
). The good thing is that it looks likeUIControlEventEditingChanged
is fired exactly at desired moments: when user presses "Done" on dictation view and when service is committing or ending dictation. So this is my best concept so far. The bad thing is that this is fired in other cases too and there is no information to distinguish in which case this control event was fired, so I don't know should I disable or enable the button or do nothing.