With the introduction of iOS 7, applications have to request microphone access when they want to record audio.
How do I check if the application has access to the microphone?
In the iOS 8 SDK I can use the AVAudioSessionRecordPermission
enum, but how do I check this in iOS 7?
Info:
I don't want to request permission, I just want to check if the app has access to the microphone. (Like Location access):
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied) { // Do something }
Settings > Apps & Notifications > Scroll down and click Advanced > Permission Manager > Select which settings you'd like to examine, from call logs, to camera permissions, to microphone permissions > Once you're under a category, you can click on any of the apps to toggle the permission to Allow or Deny.
First, open the “Settings” app. In “Settings,” tap “Privacy.” In “Privacy,” tap “Microphone.” On the next screen, you'll see a list of installed apps that have previously requested access to your microphone.
Specifically, certain apps on Android could access your microphone without your permission, meaning that whatever audio your phone's microphone can pick up, from conversations with loved ones and meetings at work to the sound of your dog barking, could be recorded and stored without you ever knowing.
You can check the with recordPermission(), which has been available since iOS 8.
Keep in mind that starting with iOS 10, you must set the NSMicrophoneUsageDescription
property in your info.plist
for microphone permissions and include a message for the user. This message is shown to the user at time of the request. Finally, if localizing your app, be sure to include your plist strings for translation.
Failure to do so will result in a crash when attempting to access the microphone.
This answer has been cleaned up again for Swift 5.x
import AVFoundation switch AVAudioSession.sharedInstance().recordPermission { case .granted: print("Permission granted") case .denied: print("Permission denied") case .undetermined: print("Request permission here") AVAudioSession.sharedInstance().requestRecordPermission({ granted in // Handle granted }) @unknown default: print("Unknown case") }
Objective-C
I have tested this code with iOS 8 for the purpose of checking for microphone permission and obtaining the current state.
switch ([[AVAudioSession sharedInstance] recordPermission]) { case AVAudioSessionRecordPermissionGranted: break; case AVAudioSessionRecordPermissionDenied: break; case AVAudioSessionRecordPermissionUndetermined: // This is the initial state before a user has made any choice // You can use this spot to request permission here if you want break; default: break; }
As always, make sure to import AVFoundation
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With