13

I use (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *) to perform real-time regex validation on every character input into a UITextView.

This works well and even handles pasted text that might contain invalid characters.

But Siri doesn't seem to care for such things and dumps its dictation straight into (void)textViewDidChange:(UITextView *)theTextView, bypassing the shouldChangeTextInRange delegate and avoiding validation checks.

This seems like a security flaw to me and breaks the API flow that every other input channel follows.

Any thoughts as to how I can get Siri Dictation to comply with calling shouldChangeTextInRange ?

Suresh D
  • 4,303
  • 2
  • 29
  • 51
Sebastian Dwornik
  • 2,526
  • 2
  • 34
  • 57
  • 4
    Dunno, but it sounds like [a good bug to file](http://bugreport.apple.com). – rickster Nov 04 '14 at 15:45
  • I agree. Sounds like you should file a radar. – Robert J. Clegg Nov 04 '14 at 16:00
  • Bug reported to Apple. Let's see what happens. – Sebastian Dwornik Nov 04 '14 at 17:38
  • 1
    I see why you expect `textView:shouldChangeTextInRange:` to be fired, but, as a current solution, you can look into `UITextInput` protocol, it has several dictation-related delegates. – Sash Zats Feb 19 '15 at 11:44
  • Would love to see some updates on this question. Like how to use UITextInput, and a link to the radar so we can track the progress and up-vote it (if Apple has that concept). For now I catch textViewDidChange and just truncate the text if too long (the text from the end of the field, since I have no way to know where/what was added at that point). Not ideal. – eselk Mar 18 '15 at 23:06
  • @SebastianDwornik, Any update on this? – Iulian Onofrei Jul 21 '15 at 14:06
  • From Apple: ```Engineering has determined that your bug report (18866525) is a duplicate of another issue (18306033) and will be closed.``` – Sebastian Dwornik Jul 22 '15 at 14:15

1 Answers1

0

I think this is the answer....if:

 - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text

is called then it's a user input. So put a BOOL in there to remember if the 'shouldChange' was checked.

then, microphone input will call:

-(void)textViewDidChange:(UITextView *)textView

check your BOOL in here and if it's NO, then it's a microphone input.

(make the BOOL = NO at the end of textViewDidChange:)

That works great for me.

Andrew Bennett
  • 910
  • 11
  • 11