我有一个用于初始麦克风的检测权限代码,然后是用于打开新视图的语音识别。 但是下面的代码创建了一个错误,例如“此应用程序在从主线程访问引擎后从后台线程修改自动布局引擎。这可能导致引擎损坏和奇怪的崩溃。”
有人可以有任何想法吗?
if (@available(iOS 10.0, *)) {
[[AVAudioSession sharedInstance] requestRecordPermission:^(BOOL granted) {
if (granted) {
// [self detechUserSpeechPermission];
// [self configureSpeechToTextView];
[SFSpeechRecognizer requestAuthorization:^(SFSpeechRecognizerAuthorizationStatus status) {
switch (status) {
case SFSpeechRecognizerAuthorizationStatusAuthorized:
[self configureSpeechToTextView];
break;
case SFSpeechRecognizerAuthorizationStatusDenied:
[self warnUserForSpeechPermission];
break;
case SFSpeechRecognizerAuthorizationStatusNotDetermined:
[self warnUserForSpeechPermission];
break;
case SFSpeechRecognizerAuthorizationStatusRestricted:
[self warnUserForSpeechPermission];
break;
default: break;
} }];
}
else {
[self warnUserForMicrophonePermission];
}
}];
} else {
NSLog(@"low ios version");
}
答案 0 :(得分:0)
尝试在主线程上调用方法,如下面的代码:
dispatch_async(dispatch_get_main_queue(), ^{
[self configureSpeechToTextView];
});