SFSpeechRecognizer.AuthorizationStatus 属性

定义

语音识别的用户权限的当前状态。

public static Speech.SFSpeechRecognizerAuthorizationStatus AuthorizationStatus { [Foundation.Export("authorizationStatus")] get; }
member this.AuthorizationStatus : Speech.SFSpeechRecognizerAuthorizationStatus

属性值

其默认值为 NotDetermined

属性

注解

与涉及隐私的其他因素一样,用户必须积极允许应用访问语音识别。

使用语音识别的应用必须在其 info.plist 文件中添加以下密钥以及相应的说明:

<key>NSSpeechRecognitionUsageDescription</key>
<string>Speech recognition will be used to determine which words you speak into this device's microphone.</string>          

如果应用程序没有此密钥,操作系统将在运行时执行“无提示”关闭,没有异常或记录错误的能力。

字符串的值 info.plist 将呈现给用户以响应 RequestAuthorization(Action<SFSpeechRecognizerAuthorizationStatus>) 方法:

if (SFSpeechRecognizer.AuthorizationStatus != SFSpeechRecognizerAuthorizationStatus.Authorized)
{
	SFSpeechRecognizer.RequestAuthorization((status) => 
	{
	   switch (status)
	   {
		   case SFSpeechRecognizerAuthorizationStatus.Authorized:
			   InvokeOnMainThread(() => prepareButton.Enabled = true);
			   break;
		   case SFSpeechRecognizerAuthorizationStatus.Restricted:
		   case SFSpeechRecognizerAuthorizationStatus.NotDetermined:
		   case SFSpeechRecognizerAuthorizationStatus.Denied:
				 InvokeOnMainThread(() => prepareButton.Enabled = false);
			   break;
	   }
    });
}

适用于