Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Microphone not working on iOS 7

Tags:

ios

ios7

I would like to ask about the problem with a simple microphone volume level detection. My code works just fine with iOS 6 or lower but not iOS 7, my code looks like this:

-(void)viewDidLoad{


NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys:
                              [NSNumber numberWithFloat: 44100.0],                 AVSampleRateKey,
                              [NSNumber numberWithInt: kAudioFormatAppleLossless], AVFormatIDKey,
                              [NSNumber numberWithInt: 1],                         AVNumberOfChannelsKey,
                              [NSNumber numberWithInt: AVAudioQualityMax],         AVEncoderAudioQualityKey,
                              nil];

    NSError *error;

    recorder = [[AVAudioRecorder alloc] initWithURL:url settings:settings error:&error];

    if (recorder) {
        [recorder prepareToRecord];
        recorder.meteringEnabled = YES;
        [recorder record];


    } else{
        NSLog([error description]);
    }

}
// then call periodically with the following method, volumeLevelSampling
-(void)volumeLevelSampling{

    [recorder updateMeters];
    NSLog(@"Average input: %f Peak input: %f", [recorder averagePowerForChannel:0], [recorder peakPowerForChannel:0]);


}

It works perfectly fine in iOS 6, however it's not sampling anything in iOS 7. The result is always -120.

like image 239
Eric Poon Avatar asked Oct 02 '13 07:10

Eric Poon


People also ask

Why is my mic not working on iPhone 7?

Possible solutions to your iPhone 7 microphone problem. Common factors that are tied to microphone issues on the iPhone are cellular connection errors, rogue apps, and damaged microphone component on your device.

Why is my iOS microphone not working?

There are many reasons the iPhone microphone may not be working. The problem may be Bluetooth or app-related, the iOS is out-of-date, or something is blocking or interfering with the microphone and preventing it from performing normally.

Why can't I hear or talk on my iPhone 7?

Go to Settings > Sounds (or Settings > Sounds & Haptics), and drag the Ringer and Alerts slider back and forth a few times. If you don't hear any sound, or if your speaker button on the Ringer and Alerts slider is dimmed, your speaker might need service.


2 Answers

Check in Settings if you have activated the permissions for your application. This works like the push notifications.

Once the alert is answered it wont pop up again. You have to go to: Settings -> Privacy -> Microphone Then check the state of your app.

If you can't see your app there, it means that you are not correctly requesting access to the microphone. Try this.

if([[AVAudioSession sharedInstance] respondsToSelector:@selector(requestRecordPermission:)]) {
    [[AVAudioSession sharedInstance] requestRecordPermission:^(BOOL granted) {
        if (!granted) {
            NSLog(@"User will not be able to use the microphone!");
        }
    }];
}

Hope it helps as a clue.

Cheers!

like image 147
Manuel M. Avatar answered Sep 21 '22 23:09

Manuel M.


In iOS 7 users must provide consent to apps that access the microphone.

Before you can use AVAudioRecorder you must first request this consent. This is done using the requestAccessForMediaType:completionHandler: method on AVCaptureDevice.

If you don't have consent - or you haven't requested it - you'll get silence when trying to record anything on iOS 7.

like image 43
lxt Avatar answered Sep 20 '22 23:09

lxt