Edit

Share via


SFSpeechRecognizer.RequestAuthorization Method

Definition

Asynchronously presents a system dialogue to the user requesting access.

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

Parameters

Attributes

Remarks

As with other facilities involving privacy, the user must positively permit the app to access speech recognition.

Apps that use speech recognition must add the following key, with appropriate descriptions, in their info.plist file:

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

If an application does not have this key, the operating system will execute a "silent" shutdown at runtime, with no exception or ability to log the mistake.

The value of the info.plist string is presented to the user in response to the RequestAuthorization(Action<SFSpeechRecognizerAuthorizationStatus>) method:

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

Applies to