使用 AVAudioRecorder 在后台录制语音(当我点击主页按钮时)

SBM*_*SBM 4 xcode objective-c

我是 IOS 开发新手。我正在尝试使用 AVAudioRecorder 在后台录制用户语音,但我向 UIBackgroundModes 添加了“音频”,但这无济于事。顺便说一句,一切都在前台工作得很好。在后台时,计时器工作正常,但没有录制声音。我如何从背景中的麦克风录音?这可能吗?

mr.*_*fox 5

You can. Skype does this.

You presumably need to set <key>UIBackgroundModes</key><array><string>audio</string></array> in Info.plist, and you need to make sure that the audio session is active/running/whatever before you switch apps (the assumption is that you won't suddenly start recording/playing music/whatever when your app is in the background).

The docs say that "audio" lets you play audio in the background, but presumably this also applies to recording audio. If it doesn't work, there are a few things you could try:

  • Set both "voip" and "audio".
  • Play silence (this might be easiest to do with the Audio Queue API).

This material from here:iOS multitasking for an Audio Recording application

额外的材料见这个:只要我按下“主页”按钮,他的录音就会停止 构建背景感知应用程序