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.
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.
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.
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.
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!
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.
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