gpt4 book ai didi

ios - 解决听写/自定义 TextView 错误

转载 作者:可可西里 更新时间:2023-11-01 05:54:43 32 4
gpt4 key购买 nike

我有一个实现 UIKeyInput 并覆盖 shouldBecomeFirstResponder 以返回 YES 的 View 。点击此 View 时,键盘会弹出。如果用户点击听写按钮,按下完成,然后尝试关闭键盘,应用程序会崩溃并显示:

Fatal Exception: NSInternalInconsistencyException NSInternalInconsistencyException
We were never set up properly to stream in this document.

我想知道是否有人知道解决此错误的方法?我尝试实现 UITextInput 并将与听写相关的方法留空,这确实有效。但是,当用户尝试使用听写并放入垃圾时,UITextInput 正在访问我的 insertText 方法。我还没有准备好实现听写,所以我实际上只是想通过某种变通暂时禁用它。任何输入将不胜感激!

最佳答案

实际上,实现 UITextInput 解决了这个问题。当用户成功听写时,它只会向您的 insertText 方法发送一个空格(不确定如何让听写在自定义 TextView 中正常工作,现在我只想修复这个错误)。下面我列出了 UITextInput 必须使用的所有方法和属性,以节省您的时间:

属性:

@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;

方法:

- (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;
}

关于ios - 解决听写/自定义 TextView 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20980898/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com