Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Microphone Option Not in App Settings Even Though Permission was Given

Tags:

I'm having a weird issue with asking for permission to the microphone on iOS 10. I put the proper plist property (Privacy - Microphone Usage Description) and enabling it through code. On my phone, the microphone works/enabled and I see it in my phone's settings for the app. However, on a friend's phone, the microphone asks for permission but then the microphone option doesn't show up in the app's settings. Am I missing something here even though I set the permissions correctly? Why would my phone show the option in the settings but not my friend's phone? I have an iPhone SE and my friend has an iPhone 6s.

plist property:

<key>NSMicrophoneUsageDescription</key>
<string>Used to capture microphone input</string>

code asking for permission:

if ([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio] == AVAuthorizationStatusAuthorized) {
    [self configureMicrophone];
}
else {
    UIAlertController *deniedAlert = [UIAlertController alertControllerWithTitle:@"Use your microphone?"
                                                                         message:@"The FOO APP requires access to your microphone to work!"
                                                                  preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *action = [UIAlertAction actionWithTitle:@"Go to Settings" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action){
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
    }];
    [deniedAlert addAction:action];
    [self presentViewController:deniedAlert animated:YES completion:nil];
}

Thanks!

like image 379
yun Avatar asked Dec 05 '16 02:12

yun


People also ask

Why do I not have mic mode on my iPhone?

If you're using any of the compatible apps but still don't see Mic Mode appear inside Control Center, chances are that you're not on a video or voice call.

Can apps access microphone without permission?

Apps could be secretly accessing your smartphone's microphone and camera to spy on you, or collect data to serve you targeted ads. To protect yourself, you can download an app that lets you know when the microphone or camera are turned on. You can also invest in some hardware to block out the microphone and camera.


1 Answers

Your code isn't correct. You check to see if the user already has permission. If it doesn't, you don't ask for permission. You simply show an alert with an option to go to the settings page. But there won't be a microphone setting on the Settings page if your app never requests permission to use the microphone.

You need code that actually requests permission. I have the following code I use for dealing with microphone permission:

+ (void)checkMicrophonePermissions:(void (^)(BOOL allowed))completion {
    AVAudioSessionRecordPermission status = [[AVAudioSession sharedInstance] recordPermission];
    switch (status) {
        case AVAudioSessionRecordPermissionGranted:
            if (completion) {
                completion(YES);
            }
            break;
        case AVAudioSessionRecordPermissionDenied:
        {
            // Optionally show alert with option to go to Settings

            if (completion) {
                completion(NO);
            }
        }
            break;
        case AVAudioSessionRecordPermissionUndetermined:
            [[AVAudioSession sharedInstance] requestRecordPermission:^(BOOL granted) {
                if (granted && completion) {
                    dispatch_async(dispatch_get_main_queue(), ^{
                        completion(granted);
                    });
                }
            }];
            break;
    }

}

You can call this as follows:

[whateverUtilClass checkMicrophonePermissions:^(BOOL allowed) {
    if (allowed) {
        [self configureMicrophone];
    }
}];
like image 107
rmaddy Avatar answered Sep 22 '22 16:09

rmaddy