用户通过语音输入时,App会崩溃uitextview [英] App Crashes uitextview when user inputs via voice

查看:154
本文介绍了用户通过语音输入时,App会崩溃uitextview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户在UITextView中通过语音输入文本时,应用程序崩溃



崩溃方法



使textview成为第一响应者,方法是单击它,然后按键盘上的麦克风按钮,然后讲话,然后按完成应用程序崩溃。。



在我的情况下,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 b)




我得到了进一步的调试(通过在控制台中输入bt),它给了我


  *线程#1:tid = 0x645a4,0x000000019340a014 libsystem_kernel.dylib`__pthread_kill + 8,队列= 

'com.apple.main-thread',停止原因=信号SIGABRT
帧#0:0x000000019340a014 libsystem_kernel.dylib __ pthread_kill + 8
框架#0:0x00000001934d1460 libsystem_pthread.dylib
pthread_kill + 112
框架#2:0x000000019337e3f4 libsystem_c.dylib 中止+ 140
帧#3:0x0000000192e492d4 libc ++ abi.dylib
abort_message + 132
帧#4:0x0000000192e66cc0 libc ++ abi.dylib defa ult_terminate_handler()+ 304
框架#5:0x0000000192e74844 libobjc.A.dylib
_objc_terminate()+ 124
框架6:0x0000000192e6366c libc ++ abi.dylib std :: __ terminate(void(*)())+ 16
帧#7:0x0000000192e62f84 libc ++ abi.dylib
__ cxa_throw + 136
帧#8:0x0000000192e74690 libobjc.A.dylib objc_exception_throw + 364
框架#9:0x000000019443c108 CoreFoundation
+ [NSException提高:格式:] + 116
框架#10:0x00000001943d9b18 CoreFoundation mutateError + 132
frame#11:0x000000019a58d138 UIKit
-[UIScrollView description] + 104
frame#12:0x0000000194e1a3c4 Foundation _NSDescriptionWithLocaleFunc + 108
框架#13:0x00000001943fd958 CoreFoundation
__ CFStringAppendFormatCore + 7996
框架#14:0x00000001943fb9e4 CoreFoundation _CFStringCreateWithFormatAndArgumentsAux2 + 244
框架# 15:0x0000000194e1a218 Foundation
+ [NSString stringWithFormat:] + 68
帧#16:0x000000019aa9aac8 UIKit -[UIDictationController insertSerializedDictationResult:withCorrectionIdentifier:] + 144
帧#17:0x000000019aa9b270 UIKit
__ 98- [UIDictationController
finishDictationRecognitionWithPhrases:languageModel:correctionIdentifier:] _ block_invoke
+ 464
frame#18:0x000000019aa9a0b4 UIKit -[UIDictationController performIgnoringDocumentChanges:] + 48
框架#19:0x000000019aa97680 UIKit
-[UIDictationController _runFinalizeOperation:] + 56
框架#20:0x000000019aa979f0 UIKit - [UIDictationController setState:] + 612
frame#21:0x000000019aa9afd0 UIKit
-[UIDictationController finishDictationRecognitionWithPhrases:languageModel:correctionIdentifier:]
+ 552
frame#22:0x000000019aa9b50c UIKit -[UIDictationController dictationConn ection:didRecognizePhrases:languageModel:correctionIdentifier:]
+ 204
框架#23:0x000000019cdbf800 AssistantServices
__ 105- [AFDictationConnection
_tellSpeechDelegateDidRecognizeSpeechb = Bokek_block_languageModel: $ b + 80
框架#24:0x000000019cdbf064 AssistantServices -[AFDictationConnection
_dispatchCallbackGroupBlock:] + 240
框架#25:0x000000019cdbf74c AssistantServices
- [AFDictationConnection
_tellSpeechDelegateDidRecognizeSpeechPhrases:languageModel:correctionIdentifier:]
+ 356
框架#26:0x000000019cdc4354 AssistantServices __ 101- [AFDictationConnectionServiceDelegate
pepeDelegate: _block_invoke
+ 76
框架#27:0x00000001005e925c libdispatch.dylib
_dispatch_call_block_and_release + 24
框架#28:0x00000001005e921c libdispatch.dylib _dispatch_client_callout + 16
框架#29:0x00000001005ee284 libdispatch.dylib
_dispatch_main_queue_callback_4CF + 1200
框架#30:0x00000001943e9f2c CoreFoundation __ CFRUNLOOP_TCH_TCH_DIAIN 12 #31:0x00000001943e7b18 CoreFoundation __ CFRunLoopRun + 1660
框架#32:0x0000000194316048 CoreFoundation CFRunLoopRunSpecific + 444
框架#33:0x0000000195d99198 GraphicsServices
GSEventRunModal + 180
框架#34:0x000000019a2e9628 UIKit -[UIApplication _run] + 684
框架#35:0x000000019a2e4360 UIKit
UIApplicationMain + 208
*帧#36:0x00000001001e03c4 motto-mobile main(argc = 1,argv = 0x000000016fdd3ab8)+ 124 at main.m:16
帧#37:0x00000001932f85b8 libdyld.dylib
开始+ 4


使用的代码

  @property(强,非原子)UIText查看* addressTextView; 
-(void)viewDidLoad {
[super viewDidLoad];
addressTextView.delegate =自我;
addressTextView.text = [self.dictionaryEditObject objectForKey:@ location];
}
-(void)textViewDidBeginEditing:(UITextView *)textView
{

}
-(BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
NSLog(@ textViewShouldBeginEditing:);

返回是;
}

-(void)textViewDidEndEditing:(UITextView *)textView
{
NSLog(@ textViewDidEndEditing);
}




上尝试iOS:10.2,9.3
设备:iPad,iPod,iPhone 5s
每台设备崩溃



任何帮助将不胜感激
谢谢

解决方案

首先要做的是对UITextView进行子类化,并在该子类中重写func accessibilityActivate()-> Bool。然后创建一个处理TextView激活时发生的委托,并通过重写的方法对其进行调用。



然后根据UIAccessibilityIsVoiceOverRunning()设置TextView的委托,因此如果正在运行画外音,则将UITextViewDelegate设置为nil,以防止崩溃发生,然后激活动作由您在上述子类中覆盖的方法处理。最后,为UIAccessibilityVoiceOverStatusChanged设置一个侦听器,并从关闭状态切换为打开状态时将UITextViewDelegate设置为nil,然后将其设置为相反情况下的原始委托类。


App crashes when user inputs text via voice in UITextView,

Crash Method

make textview first responder by clicking on it then Press on mic button in keyboard then speech something then press Done the app crashes..

Nothing special is done with uitextview in my case..

Console Output

*

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Attempt to mutate immutable object with deleteCharactersInRange:'

  • First throw call stack: (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: terminating with uncaught exception of type NSException

on further debugging i got (by entering bt in console) it gives me

* thread #1: tid = 0x645a4, 0x000000019340a014 libsystem_kernel.dylib`__pthread_kill + 8, queue =

'com.apple.main-thread', stop reason = signal SIGABRT frame #0: 0x000000019340a014 libsystem_kernel.dylib__pthread_kill + 8 frame #1: 0x00000001934d1460 libsystem_pthread.dylibpthread_kill + 112 frame #2: 0x000000019337e3f4 libsystem_c.dylibabort + 140 frame #3: 0x0000000192e492d4 libc++abi.dylibabort_message + 132 frame #4: 0x0000000192e66cc0 libc++abi.dylibdefault_terminate_handler() + 304 frame #5: 0x0000000192e74844 libobjc.A.dylib_objc_terminate() + 124 frame #6: 0x0000000192e6366c libc++abi.dylibstd::__terminate(void (*)()) + 16 frame #7: 0x0000000192e62f84 libc++abi.dylib__cxa_throw + 136 frame #8: 0x0000000192e74690 libobjc.A.dylibobjc_exception_throw + 364 frame #9: 0x000000019443c108 CoreFoundation+[NSException raise:format:] + 116 frame #10: 0x00000001943d9b18 CoreFoundationmutateError + 132 frame #11: 0x000000019a58d138 UIKit-[UIScrollView description] + 104 frame #12: 0x0000000194e1a3c4 Foundation_NSDescriptionWithLocaleFunc + 108 frame #13: 0x00000001943fd958 CoreFoundation__CFStringAppendFormatCore + 7996 frame #14: 0x00000001943fb9e4 CoreFoundation_CFStringCreateWithFormatAndArgumentsAux2 + 244 frame #15: 0x0000000194e1a218 Foundation+[NSString stringWithFormat:] + 68 frame #16: 0x000000019aa9aac8 UIKit-[UIDictationController insertSerializedDictationResult:withCorrectionIdentifier:] + 144 frame #17: 0x000000019aa9b270 UIKit__98-[UIDictationController finishDictationRecognitionWithPhrases:languageModel:correctionIdentifier:]_block_invoke + 464 frame #18: 0x000000019aa9a0b4 UIKit-[UIDictationController performIgnoringDocumentChanges:] + 48 frame #19: 0x000000019aa97680 UIKit-[UIDictationController _runFinalizeOperation:] + 56 frame #20: 0x000000019aa979f0 UIKit-[UIDictationController setState:] + 612 frame #21: 0x000000019aa9afd0 UIKit-[UIDictationController finishDictationRecognitionWithPhrases:languageModel:correctionIdentifier:] + 552 frame #22: 0x000000019aa9b50c UIKit-[UIDictationController dictationConnection:didRecognizePhrases:languageModel:correctionIdentifier:] + 204 frame #23: 0x000000019cdbf800 AssistantServices__105-[AFDictationConnection _tellSpeechDelegateDidRecognizeSpeechPhrases:languageModel:correctionIdentifier:]_block_invoke + 80 frame #24: 0x000000019cdbf064 AssistantServices-[AFDictationConnection _dispatchCallbackGroupBlock:] + 240 frame #25: 0x000000019cdbf74c AssistantServices-[AFDictationConnection _tellSpeechDelegateDidRecognizeSpeechPhrases:languageModel:correctionIdentifier:] + 356 frame #26: 0x000000019cdc4354 AssistantServices__101-[AFDictationConnectionServiceDelegate speechDidRecognizePhrases:usingSpeechModel:correctionContext:]_block_invoke + 76 frame #27: 0x00000001005e925c libdispatch.dylib_dispatch_call_block_and_release + 24 frame #28: 0x00000001005e921c libdispatch.dylib_dispatch_client_callout + 16 frame #29: 0x00000001005ee284 libdispatch.dylib_dispatch_main_queue_callback_4CF + 1200 frame #30: 0x00000001943e9f2c CoreFoundation__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12 frame #31: 0x00000001943e7b18 CoreFoundation__CFRunLoopRun + 1660 frame #32: 0x0000000194316048 CoreFoundationCFRunLoopRunSpecific + 444 frame #33: 0x0000000195d99198 GraphicsServicesGSEventRunModal + 180 frame #34: 0x000000019a2e9628 UIKit-[UIApplication _run] + 684 frame #35: 0x000000019a2e4360 UIKitUIApplicationMain + 208 * frame #36: 0x00000001001e03c4 motto-mobilemain(argc=1, argv=0x000000016fdd3ab8) + 124 at main.m:16 frame #37: 0x00000001932f85b8 libdyld.dylibstart + 4

Code used

@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");
}

tried on iOS: 10.2,9.3 device: iPad, iPod, iPhone 5s crash on every device

Any Help Would be appreciated Thanks

解决方案

The first thing to do is to subclass UITextView and in that subclass override func accessibilityActivate() -> Bool. Then make a delegate that handles what happens when the TextView is activated and call it through the overridden method.

Then set the delegate of the TextView based on UIAccessibilityIsVoiceOverRunning(), so if voice over is running then set the UITextViewDelegate to nil which prevents the crash from happening and then the activation action is handled by the method you overrode in the subclass above. Finally, set up a listener for UIAccessibilityVoiceOverStatusChanged and set the UITextViewDelegate to nil when going from off to on, and setting it to the original delegation class for the opposite scenario.

这篇关于用户通过语音输入时,App会崩溃uitextview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆