3

在我的设备上使用 Xcode 5.0 并运行 iOS 7.0.2。

我正在使用这种代码:

AVAudioRecorder *audioRecorder;
………
[audioRecorder recordForDuration:(NSTimeInterval)5.0];
………
- (void)audioRecorderDidFinishRecording:(AVAudioRecorder *)recorder successfully:(BOOL)flag
{
        NSLog(@"audioRecorderDidFinishRecording");
}

在模拟器上一切正常,方法 audioRecorderDidFinishRecording 在调用 recordForDuration 5 秒后按预期启动。在设备上,虽然它永远不会启动。为什么会这样?任何想法?

我在网上看到过类似的问题,但不完全是这个,更重要的是没有对我有用的答案。

4

2 回答 2

3

以防其他人有同样的问题。这是我找到的解决方案:

在调用 recordForDuration 方法之前需要以下内容。

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];

奇怪的是,这在模拟器上不是问题。

于 2013-10-13T09:43:15.453 回答
1

audioRecorder.stop()也需要调用

于 2016-03-01T23:17:31.597 回答