The Vivox SDK does not have an API call to request microphone permissions or to determine if permissions have already been granted. You can determine this information by using a call provided by Unity.
The first line in the following code snippet requests microphone permission. The contents of the if statement return if the permission has been granted.
Note: Although the statements are next to each other in the example, they do not need to be used in that manner.
When you know that the user has not enabled the microphone, you can then display an error message.
// Request microphone permission
yield return Application.RequestUserAuthorization(UserAuthorization.Microphone);
// Check microphone permission
if (Application.HasUserAuthorization(UserAuthorization.Microphone))
{
Debug.Log("Microphone found");
}
else
{
Debug.Log("Microphone not found");
}
The entire example is located at Application.RequestUserAuthorization in the Unity Scripting API documentation.
In addition, starting with iOS 10, as well as on macOS, the NSMicrophoneUsageDescription
property must be included in your info.plist
that will be displayed when requesting microphone permission. If this value does not exist, your application will terminate.
You can manually add this value to the Xcode project or through the Unity iOS Player Settings, as displayed in the following image.