如何检测两种不同的权限
How to detect two different kind permission
我有一个检测权限代码,首先是麦克风,然后是语音识别以打开新视图。
但是下面的代码产生了错误,例如“从主线程访问引擎后,此应用程序正在从后台线程修改自动布局引擎。这可能导致引擎损坏和奇怪的崩溃。”
有谁知道吗?
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");
}
尝试像下面的代码那样在主线程调用方法:
dispatch_async(dispatch_get_main_queue(), ^{
[self configureSpeechToTextView];
});
我有一个检测权限代码,首先是麦克风,然后是语音识别以打开新视图。 但是下面的代码产生了错误,例如“从主线程访问引擎后,此应用程序正在从后台线程修改自动布局引擎。这可能导致引擎损坏和奇怪的崩溃。”
有谁知道吗?
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");
}
尝试像下面的代码那样在主线程调用方法:
dispatch_async(dispatch_get_main_queue(), ^{
[self configureSpeechToTextView];
});