Procedure:
The Vivox SDK does not have its own API call to request microphone permissions, or to determine if permissions have already been granted: instead, you can determine this information by using a call provided by Unity.
Prerequisites:
On macOS—and on iOS starting with iOS SDK 10—the property NSMicrophoneUsageDescription
must be included in your info.plist
. This property provides a text description that will be displayed when requesting microphone permission. If you request permissions and this value is not set, your application will terminate.
You can add this value directly to the Xcode project, or through the Unity iOS Player Settings as shown in the following image:
Code Examples:
Note: more complete example is located in the Unity Scripting API documentation for Application.RequestUserAuthorization.
Requesting microphone permissions:
The following code snippet shows a call to request microphone permission.
// Request microphone permission yield return Application.RequestUserAuthorization(UserAuthorization.Microphone);
Checking microphone permissions:
The following code snippet shows a call to check whether microphone permission was previously authorized.
If the if
statement returns true, permission has been granted. When you know that the user has not enabled the microphone, you can prompt them for permissions or display an error message.
// Check microphone permission if (Application.HasUserAuthorization(UserAuthorization.Microphone)) { Debug.Log("Microphone found"); } else { Debug.Log("Microphone not found"); }