Siri Dictation Bypasses UITextView:shouldChangeTextInRange Delegate
Asked Answered
C

1

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 ?

Corpulence answered 4/11, 2014 at 15:40 Comment(7)
Dunno, but it sounds like a good bug to file.Czerny
I agree. Sounds like you should file a radar.Zedoary
Bug reported to Apple. Let's see what happens.Corpulence
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.Honeybunch
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.Omeara
@SebastianDwornik, Any update on this?Trondheim
From Apple: Engineering has determined that your bug report (18866525) is a duplicate of another issue (18306033) and will be closed.Corpulence
I
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.

Ike answered 26/3, 2015 at 0:40 Comment(2)
Hard to understand, poor wording, and most important, didn't work. Down-voted too.Trondheim
that's the solution by the way if you don't want to dig into dictation delegates of UITextInputPhotoconduction

© 2022 - 2024 — McMap. All rights reserved.