20

i'm having some issue with AVFoundation framework. I wrote a demo app to record audio, play it, and calculate decibels, with iOS 6. It both worked with iOS simulator built-in xcode 4.6.3 and my iPhone with iOS 6.1.3

Now i've update xcode to version 5 and tested the appa again. With the built-in simulator it works (both with iOS 6.1 and iOS 7 simulators). But when i deploy the app to my iPhone, with iOS 7.0, it doesn't work anymore.

I'm using AVAudioRecorder and AVAudioPlayer.

I don't know what could be the problem. Any suggestions? thank you!

elp
  • 8,021
  • 7
  • 61
  • 120
ace_ventura
  • 468
  • 1
  • 4
  • 14
  • that's exactly what's been happening to me. All my apps that used to work on iOS 6 have just flat out stopped working in iOS 7 for AVAudioRecorder and AVAudioPlayer. In my case they don't even work on simulator – Sam B Sep 20 '13 at 23:38
  • Sam, was your app unable to play audio as well? Check my answer for the way I figured out how to fix recording, but my playback was still working prior to the fix. – Mr.Hardy Sep 22 '13 at 03:21

4 Answers4

60

I was having the same issue... It appears as if Apple is now requiring the use of AVAudioSession prior to using the AVAudioRecorder. I couldn't find any documentation on this change in requirement, however the recording portion of my app is now working.

All I did was create an audioSession, set the category, and set it to be active. I did this prior to calling prepareToRecord and I tried it after the call to prepareToRecord... both ways worked.

I hope this fixes your problem!

AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
[audioSession setActive:YES error:nil];
Vinod VT
  • 6,946
  • 11
  • 51
  • 75
Mr.Hardy
  • 909
  • 8
  • 13
  • I tried this on my code but its still not working. Do I need to ask permission to use the microphone first? thanks. – atbebtg Sep 25 '13 at 20:32
  • @atbebtg you might need to replace the category with `AVAudioSessionCategoryPlayback`. – Hank Oct 08 '13 at 03:34
  • These helped me solve problem. Thanks a lot. Should add a bit of salt. Last two methods have return value. It is not a good practice ignoring return value. It is not acceptable even in example snippets. – Valeriy Van Jan 05 '14 at 14:52
5

Same issue.

I have fixed it by using AVAudioSession. Moreover set properly the category of AVAudioSession:

when recording use:

[self.audioSession setCategory:AVAudioSessionCategoryRecord error:nil];

when playing use:

[self.audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];

If i don't switch the category when i play, the registration the volume is very low.

Good Luck!

Kundan
  • 3,084
  • 2
  • 28
  • 65
1

I am also facing this problem so First I had to make sure the app had permission to use the mic by going to settings -> privacy -> microphone then I got success.

Anil Prasad
  • 711
  • 1
  • 6
  • 16
0

Maybe you do not have access to the microphone. Use this code:

if ([audioSession respondsToSelector:@selector(requestRecordPermission:)]) {
    [audioSession performSelector:@selector(requestRecordPermission:) withObject:^(BOOL granted) {
        if (granted) {
            // Microphone enabled code
        }
        else {
            // Microphone disabled code
        }
    }];
}
Alexander
  • 9,074
  • 2
  • 15
  • 13