Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect microphone input permission refused in iOS 7

I would like to detect when a user refused the microphone permission on my iOS application. I only get this value when I try to record the microphone: -120.000000 db

But before to get this I have to set up an AVAudioSession. Is there another function?

And I got this message in the output: Microphone input permission refused - will record only silence

Thanks.

like image 739
Benoît Freslon Avatar asked Sep 05 '13 00:09

Benoît Freslon


People also ask

How do I give an app permission to use my microphone?

Allow access to microphone and camera on Android devicesSelect 'Settings > Apps > LINE WORKS' on your device. Select 'Permissions' in App info. Allow access to 'Microphone', 'Phone', and 'Camera'.

How do I give my Xbox permission to access my microphone on my iPhone?

You will need to (1) Open Settings (2) Tap Privacy (3) Tap Microphone (4) Tap the Xbox app to allow microphone access.


1 Answers

If you are still compiling with iOS SDK 6.0 (as I am) you have to be a bit more indirect than @Luis E. Prado, as the requestRecordPermission method doesn't exist.

Here's how I did it. Remove the autorelease bit if you're using ARC. On iOS6 nothing happens, and on iOS7 either the 'microphone is enabled' message is logged or the alert is popped up.

AVAudioSession *session = [AVAudioSession sharedInstance]; if ([session respondsToSelector:@selector(requestRecordPermission:)]) {     [session performSelector:@selector(requestRecordPermission:) withObject:^(BOOL granted) {         if (granted) {             // Microphone enabled code             NSLog(@"Microphone is enabled..");         }         else {             // Microphone disabled code             NSLog(@"Microphone is disabled..");              // We're in a background thread here, so jump to main thread to do UI work.             dispatch_async(dispatch_get_main_queue(), ^{                 [[[[UIAlertView alloc] initWithTitle:@"Microphone Access Denied"                                         message:@"This app requires access to your device's Microphone.\n\nPlease enable Microphone access for this app in Settings / Privacy / Microphone"                                        delegate:nil                               cancelButtonTitle:@"Dismiss"                               otherButtonTitles:nil] autorelease] show];             });         }     }]; } 

EDIT: It turns out that the withObject block is executed in a background thread, so DO NOT do any UI work in there, or your app may hang. I've adjusted the code above. A client pointed this out on what was thankfully a beta release. Apologies for the mistake.

like image 92
Ben Clayton Avatar answered Oct 07 '22 12:10

Ben Clayton