I have a view that implements UIKeyInput
and overrides shouldBecomeFirstResponder
to return YES
. When this view is tapped, the keyboard pops up. If the user taps the dictation button, pushes done, and then tries to dismiss the keyboard, the app crashes with:
Fatal Exception: NSInternalInconsistencyException NSInternalInconsistencyException We were never set up properly to stream in this document.
I was wondering if anyone knows a work around to fix this bug? I tried implementing UITextInput
and leaving dictation related methods blank and this actually works. However, UITextInput
is accessing my insertText method when the user tries to use Dictation and putting in junk. I'm not yet ready to implement dictation, so I'd actually just like to disable it for now with some sort of work around. Any input would be appreciated!
Actually, implementing UITextInput
fixes the problem. When the user does a successful dictation, it will just send a space to your insertText method (not exactly sure how to get dictation to work correctly in a custom text view, right now I'm just wanting to fix this bug). Below I've listed all the methods and properties you have to use for UITextInput
to save you some time:
Properties:
@property(nonatomic, readonly) UITextPosition *beginningOfDocument; @property(nonatomic, readonly) UITextPosition *endOfDocument; @property(nonatomic, assign) id<UITextInputDelegate> inputDelegate; @property(nonatomic, readonly) UITextRange *markedTextRange; @property(nonatomic, copy) NSDictionary *markedTextStyle; @property(readwrite, copy) UITextRange *selectedTextRange; @property(nonatomic, readonly) id<UITextInputTokenizer> tokenizer;
Methods:
- (UITextWritingDirection)baseWritingDirectionForPosition:(UITextPosition *)position inDirection:(UITextStorageDirection)direction { return nil; } - (CGRect)caretRectForPosition:(UITextPosition *)position { return CGRectZero; } - (void)unmarkText { } - (UITextRange *)characterRangeAtPoint:(CGPoint)point { return nil; } - (UITextRange *)characterRangeByExtendingPosition:(UITextPosition *)position inDirection:(UITextLayoutDirection)direction { return nil; } - (UITextPosition *)closestPositionToPoint:(CGPoint)point { return nil; } - (UITextPosition *)closestPositionToPoint:(CGPoint)point withinRange:(UITextRange *)range { return nil; } - (NSComparisonResult)comparePosition:(UITextPosition *)position toPosition:(UITextPosition *)other { return nil; } - (void)dictationRecognitionFailed { } - (void)dictationRecordingDidEnd { } - (CGRect)firstRectForRange:(UITextRange *)range { return CGRectZero; } - (CGRect)frameForDictationResultPlaceholder:(id)placeholder { return CGRectZero; } - (void)insertDictationResult:(NSArray *)dictationResult { } - (id)insertDictationResultPlaceholder { return nil; } - (NSInteger)offsetFromPosition:(UITextPosition *)fromPosition toPosition:(UITextPosition *)toPosition { return nil; } - (UITextPosition *)positionFromPosition:(UITextPosition *)position inDirection:(UITextLayoutDirection)direction offset:(NSInteger)offset { return nil; } - (UITextPosition *)positionFromPosition:(UITextPosition *)position offset:(NSInteger)offset { return nil; } - (UITextPosition *)positionWithinRange:(UITextRange *)range farthestInDirection:(UITextLayoutDirection)direction { return nil; } - (void)removeDictationResultPlaceholder:(id)placeholder willInsertResult:(BOOL)willInsertResult { } - (void)replaceRange:(UITextRange *)range withText:(NSString *)text { } - (NSArray *)selectionRectsForRange:(UITextRange *)range { return nil; } - (void)setBaseWritingDirection:(UITextWritingDirection)writingDirection forRange:(UITextRange *)range { } - (void)setMarkedText:(NSString *)markedText selectedRange:(NSRange)selectedRange { } - (NSString *)textInRange:(UITextRange *)range { return nil; } - (UITextRange *)textRangeFromPosition:(UITextPosition *)fromPosition toPosition:(UITextPosition *)toPosition { return nil; }