当用户在UITextView中通过语音输入文本时,应用程序崩溃,
崩溃方法
点击文本查看第一响应者然后按键盘上的麦克风按钮然后按语音然后按完成应用程序崩溃..
在我的案例中没有使用uitextview做任何特别的事情..
控制台输出
*
由于未捕获的异常而终止应用 'NSInvalidArgumentException',原因:'尝试变异不可变 具有deleteCharactersInRange的对象:'
第一次抛出调用堆栈:(0x19443c1c0 0x192e7455c 0x19443c108 0x1943d9b18 0x19a58d138 0x194e1a3c4 0x1943fd958 0x1943fb9e4 0x194e1a218 0x19aa9aac8 0x19aa9b270 0x19aa9a0b4 0x19aa97680 0x19aa979f0 0x19aa9afd0 0x19aa9b50c 0x19cdbf800 0x19cdbf064 0x19cdbf74c 0x19cdc4354 0x1005e925c 0x1005e921c 0x1005ee284 0x1943e9f2c 0x1943e7b18 0x194316048 0x195d99198 0x19a2e9628 0x19a2e4360 0x1001e03c4 0x1932f85b8)libc ++ abi.dylib:终止于 NSException类型的未捕获异常
进一步调试我(通过在控制台中输入bt)它给了我
* thread #1: tid = 0x645a4, 0x000000019340a014 libsystem_kernel.dylib`__pthread_kill + 8, queue =
'com.apple.main-thread',stop reason = signal SIGABRT 帧#0:0x000000019340a014 libsystem_kernel.dylib
__pthread_kill + 8 frame #1: 0x00000001934d1460 libsystem_pthread.dylib
pthread_kill + 112 帧#2:0x000000019337e3f4 libsystem_c.dylibabort + 140 frame #3: 0x0000000192e492d4 libc++abi.dylib
abort_message + 132 第4帧:0x0000000192e66cc0 libc ++ abi.dylibdefault_terminate_handler() + 304 frame #5: 0x0000000192e74844 libobjc.A.dylib
_ objc_terminate()+ 124 帧#6:0x0000000192e6366c libc ++ abi.dylibstd::__terminate(void (*)()) + 16 frame #7: 0x0000000192e62f84 libc++abi.dylib
__ cxa_throw + 136 帧#8:0x0000000192e74690 libobjc.A.dylibobjc_exception_throw + 364 frame #9: 0x000000019443c108 CoreFoundation
+ [NSException raise:format:] + 116 帧#10:0x00000001943d9b18 CoreFoundationmutateError + 132 frame #11: 0x000000019a58d138 UIKit
- [UIScrollView description] + 104 第12帧:0x0000000194e1a3c4基金会_NSDescriptionWithLocaleFunc + 108 frame #13: 0x00000001943fd958 CoreFoundation
__ CFStringAppendFormatCore + 7996 帧#14:0x00000001943fb9e4 CoreFoundation_CFStringCreateWithFormatAndArgumentsAux2 + 244 frame #15: 0x0000000194e1a218 Foundation
+ [NSString stringWithFormat:] + 68 帧#16:0x000000019aa9aac8 UIKit-[UIDictationController insertSerializedDictationResult:withCorrectionIdentifier:] + 144 frame #17: 0x000000019aa9b270 UIKit
__ 98- [UIDictationController finishDictationRecognitionWithPhrases:语言模型:correctionIdentifier:] _ block_invoke + 464 帧#18:0x000000019aa9a0b4 UIKit-[UIDictationController performIgnoringDocumentChanges:] + 48 frame #19: 0x000000019aa97680 UIKit
- [UIDictationController _runFinalizeOperation:] + 56 帧#20:0x000000019aa979f0 UIKit-[UIDictationController setState:] + 612 frame #21: 0x000000019aa9afd0 UIKit
- [UIDictationController finishDictationRecognitionWithPhrases:languageModel:correctionIdentifier:] + 552 帧#22:0x000000019aa9b50c UIKit-[UIDictationController dictationConnection:didRecognizePhrases:languageModel:correctionIdentifier:] + 204 frame #23: 0x000000019cdbf800 AssistantServices
__ 105- [AFDictationConnection _tellSpeechDelegateDidRecognizeSpeechPhrases:语言模型:correctionIdentifier:] _ block_invoke + 80 帧#24:0x000000019cdbf064 AssistantServices-[AFDictationConnection _dispatchCallbackGroupBlock:] + 240 frame #25: 0x000000019cdbf74c AssistantServices
- [AFDictationConnection _tellSpeechDelegateDidRecognizeSpeechPhrases:语言模型:correctionIdentifier:] + 356 帧#26:0x000000019cdc4354 AssistantServices__101-[AFDictationConnectionServiceDelegate speechDidRecognizePhrases:usingSpeechModel:correctionContext:]_block_invoke + 76 frame #27: 0x00000001005e925c libdispatch.dylib
_ dispatch_call_block_and_release + 24 帧#28:0x00000001005e921c libdispatch.dylib_dispatch_client_callout + 16 frame #29: 0x00000001005ee284 libdispatch.dylib
_ dispatch_main_queue_callback_4CF + 1200 帧#30:0x00000001943e9f2c CoreFoundation__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12 frame #31: 0x00000001943e7b18 CoreFoundation
__ CFRunLoopRun + 1660 帧#32:0x0000000194316048 CoreFoundationCFRunLoopRunSpecific + 444 frame #33: 0x0000000195d99198 GraphicsServices
GSEventRunModal + 180 帧#34:0x000000019a2e9628 UIKit-[UIApplication _run] + 684 frame #35: 0x000000019a2e4360 UIKit
UIApplicationMain + 208 *帧#36:0x00000001001e03c4 motto-mobilemain(argc=1, argv=0x000000016fdd3ab8) + 124 at main.m:16 frame #37: 0x00000001932f85b8 libdyld.dylib
start + 4
使用的代码
@property(strong,nonatomic) UITextView *addressTextView;
- (void)viewDidLoad {
[super viewDidLoad];
addressTextView.delegate = self;
addressTextView.text = [self.dictionaryEditObject objectForKey:@"location"];
}
-(void)textViewDidBeginEditing:(UITextView *)textView
{
}
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
NSLog(@"textViewShouldBeginEditing:");
return YES;
}
-(void)textViewDidEndEditing:(UITextView *)textView
{
NSLog(@"textViewDidEndEditing");
}
试了一下 iOS:10.2,9.3 设备:iPad,iPod,iPhone 5s 在每台设备上崩溃
任何帮助将不胜感激 感谢
答案 0 :(得分:0)
要做的第一件事是继承UITextView并在该子类中覆盖func accessibilityActivate() - >布尔。然后创建一个委托来处理激活TextView时发生的事情并通过重写方法调用它。
然后根据UIAccessibilityIsVoiceOverRunning()设置TextView的委托,因此如果正在运行语音,则将UITextViewDelegate设置为nil,以防止崩溃发生,然后激活操作由您在上面的子类中覆盖的方法处理。最后,为UIAccessibilityVoiceOverStatusChanged设置一个监听器,并在从off到on时将UITextViewDelegate设置为nil,并将其设置为相反方案的原始委托类。