共用方式為


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

適用於