Reputation: 1823
I have a problem with pausing AVAudioRecorder after entering background. Basically, it goes like this (_recorder is my AVAudioRecorder instance):
Start recording:
[_recorder record];
Press the home button on the device.
In applicationDidEnterBackground I do:
[_recorder pause];
Now, when I tap application icon, to take app to foreground, recording continous immediately, without taking any action. It's even stranger, because checking property:
_recorder.recording == YES
returns NO.
I have a function, that is called by NSTimer every 0.1s (to refresh UI etc.), and in that function I have this:
if(_recorder.recording) {
NSLog(@"recording");
}
else {
NSLog(@"not recording");
NSLog(@"time: %f", _recorder.currentTime);
}
It prints on the console:
...
not recording
time: 9.404082
not recording
not recording
time: 9.473197
not recording
time: 9.531179
not recording
time: 9.629206
not recording
time: 9.728435
...
So, as you can see, the recorder's currentTime increases all the time, and the audio is being recorded.
Any Idea how to solve this?
Upvotes: 2
Views: 1760
Reputation: 1570
You should add the following code:
<key>UIBackgroundModes</key>
<array>
<string>audio</string>
</array>
to the Info.plist. This will cause the background mode to be responsive for managing audio session, so you can manually pause and resume recording.
Upvotes: 7