In case someone else has the same issue. Here is the solution I found:
One needs the following before calling the recordForDuration method.
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
Strangely enough this is not an issue on the simulator.