- Home /
Microphone on iOS check if permission given
I can't find any way of checking if the user has given the app permission to use the microphone. I'm recording like this:
audio.clip = Microphone.Start("Built-in Microphone", true, LOOPLENGTH, AudioSettings.outputSampleRate);
audio.loop = true;
while (!(Microphone.GetPosition("Built-in Microphone") > 0)) {
} audio.Play();
which works fine. but if the user has not granted permission then there doesn't seem to be any way of checking, in order to behave differently (or show an alert, etc)
I've tried checking if Microphone.Start returns null, but when permission is turned off it still returns non-null.
I've also tried checking Microphone.IsRecording, but that seems to return true even when permission is turned off as well.
edit:
i ended up using a (very) hacky workaround, checking the power of the mic input every update and assuming permission is denied if it's zero:
samples = new float[SAMPLECOUNT];
audio.GetOutputData(samples, 0);
double rmsCalc = 0;
for (int i = 0; i < SAMPLECOUNT; i++) {
rmsCalc += Mathf.Pow(samples[i], 2);
}
rmsCalc = Math.Sqrt(rmsCalc/(double)SAMPLECOUNT);
if (rmsCalc < 0.0000000000000000000000000000000000000001f) {
micOff = true;
}
else {
micOff = false;
}
I'm having the same issue. To add to the "things that have been tested" I tried Application.HasUserAuthorization check which you would assume is the place to start when asking for permissions but this doesn't seem to work on iOS.
see hacky way of doing it in the edit above... might work for some use cases. it would be great to be able to check it properly though
I would like to have a "non-hacky" solution for this issue too.
I would like to have a "real" method for this checking too.
Answer by RMGK · Jun 21, 2017 at 09:56 PM
https://forum.unity3d.com/threads/ios-app-never-asks-for-microphone-permissions.450307/
Application.HasUserAuthorization(UserAuthorization.Microphone); Turns out that the docs are supposed to incorrect on this issue. Should work for iOS.
Your answer
Follow this Question
Related Questions
How to use the Microphone class to record multiple AudioClip's 1 Answer
compress recorded audio in an app? 0 Answers
Unity doesn't work with Microsoft cognitive SpeechToText iOS SDK 0 Answers
How to force audio through iPhone loudspeaker when microphone is being used? 1 Answer
Microphone.Start() stops audio from playing on ios 2 Answers