Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Record voice in background(when i tapped home button) using AVAudioRecorder

I'm new in IOS development.I'm trying to record user voice in background using AVAudioRecorder but I add "audio" to UIBackgroundModes but this don't help. By the way, Everything works perfect in foreground.When in the background the timer works fine but voice is not recording. How can i record from microphone from background ? Is this possible?

like image 864
SBM Avatar asked Jan 13 '23 12:01

SBM


1 Answers

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

Extra material see this:he recording stops as soon as I press the "HOME" button Building Background-Aware Applications

like image 194
SBotirov Avatar answered Jan 16 '23 01:01

SBotirov