SFSpeechRecognizer.RequestAuthorization 方法

定义

向请求访问的用户异步显示系统对话。

[Foundation.Export("requestAuthorization:")]
public static void RequestAuthorization (Action<Speech.SFSpeechRecognizerAuthorizationStatus> handler);
static member RequestAuthorization : Action<Speech.SFSpeechRecognizerAuthorizationStatus> -> unit

参数

属性

注解

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

使用语音识别的应用必须在其 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;
	   }
    });
}

适用于