iOS background audio recording after call

I'm developing an iOS application that records audio in background. That's work fine.
The problem is when a call comes in: when i'm calling the app stops to record (that's fine) but when the call ends, I need that the app start to record again.

Is it possible ? How can I do this ?

Thanks to all.

UPDATE

I use AudioQueueNewInput to record audio. Now I'm trying to use this code to get incoming call:

AVAudioSession *session = [AVAudioSession sharedInstance];
NSError *categoryError = nil;
[session setActive: NO error: nil];
if (![session  setCategory:AVAudioSessionCategoryPlayAndRecord
               withOptions:AVAudioSessionCategoryOptionMixWithOthers
                     error:&categoryError]){
    NSLog(@"Error"); //no error
}
[session setActive: YES error: nil];
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(handleAudioSessionInterruption:)
                                             name:AVAudioSessionInterruptionNotification
                                           object:session];

I can get the ends of call on handleAudioSessionInterruption by AVAudioSessionInterruptionOptionShouldResume, but how can I restart my audio recorder?

I tried to use to call AudioQueueStart again o simply same function that I use to start to record, but I can't see the red bar (mic in use) to know that app is recording. What's wrong ?


Please see this question: Can not restart an interrupted audio input queue in background mode on iOS

Yes it is possible, but to reactivate the session in the background, the audio session has to either set AudioSessionProperty kAudioSessionProperty_OverrideCategoryMixWithOthers

OSStatus propertySetError = 0;
UInt32 allowMixing = true;
propertySetError = AudioSessionSetProperty (
                   kAudioSessionProperty_OverrideCategoryMixWithOthers,
                   sizeof (allowMixing),
                   &allowMixing);

or the app has to receive remote control command events:

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[self becomeFirstResponder];
链接地址: http://www.djcxy.com/p/79032.html

上一篇: iOS无法在扬声器上播放并设置音频会话进行录制

下一篇: 通话后iOS背景音频录制