Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by peterworth · Feb 22, 2015 at 04:49 PM · iosaudiomicrophone

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;    
 }
Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image mbaker · Mar 02, 2015 at 04:13 PM 0
Share

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.

avatar image peterworth · Mar 11, 2015 at 11:58 AM 1
Share

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

avatar image ableRex_358 · Dec 13, 2016 at 12:48 PM 0
Share

I would like to have a "non-hacky" solution for this issue too.

avatar image ableRex_358 · Dec 13, 2016 at 02:25 PM 0
Share

I would like to have a "real" method for this checking too.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

23 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges