简体   繁体   中英

iOS Background audio recording

I know that if I start an audio recording session in foreground, with Audio, Airplay, and Picture in Picture activated in Capabilities -> Background Modes; I am able to continue to record even in background, but only if I start the recording session in foreground and then I go in background.

My problem is that I want to start the voice recording session from background, which might seem shaddy and not what Apple wants, but the use case is like this:

I have a Bluetooth LE device with buttons and an iOS app. Those two are paired (Bluetooth LE device and the iPhone which runs the iOS app) and the iOS app is listening for events on the Bluetooth LE device, events like a hit of a button.

Now, when the user hits a button on the Bluetooth LE device, the iOS app captures the event and I am able to run code even if the app is in background, but I am not able to start a voice recording.

My question is: is that even possible? To start a voice recording from background? Even if we have user interaction here, not on the iOS app but on the Bluetooth LE, so it's not like the voice recording starts in background and the user is not aware of it, he pressed the button on the Bluetooth LE device, he knows what he's doing.

Any help, documentation, tweet of an Apple engineer, anything would be much appreciated. Thanks.

UPDATE: MFI is not required. https://mfi.apple.com/MFiWeb/getFAQ.action#1-2 .

If you look into the section:

"What types of accessories and technologies are NOT part of the MFi Program?"

You will see that:

"Accessories that use only Bluetooth Low Energy (BTLE) (note: BTLE-enabled HomeKit accessories and BTLE-enabled MFi Hearing Aids are part of the MFi Program)"

Is mentioned, which means MFI in this case is not required .

From Apple Documentation

An app that plays or records audio continuously (even while the app is running in the background) can register to perform those tasks in the background. You enable audio support from the Background modes section of the Capabilities tab in your Xcode project. (You can also enable this support by including the UIBackgroundModes key with the audio value in your app's Info.plist file.) Apps that play audio content in the background must play audible content and not silence.

Typical examples of background audio apps include:

Music player apps Audio recording apps Apps that support audio or video playback over AirPlay VoIP apps

For tasks that require more execution time to implement, you must request specific permissions to run them in the background without their being suspended. In iOS, only specific app types are allowed to run in the background:

  • Apps that record audio content while in the background

EDIT:

Also regarding your "Bluetooth device":

Check out the documentation for ExternalAccessory .

Be aware that you need to apply and get approved for a special developer program in order to be able to create external accessories.

Helpful tips::

It turns out that Apple's SpeakHere sample code with some modifications will start recording audio in the background if you just add the audio multitasking flag to information. You might look https://github.com/benvium/SpeakHere for an updated version of SpeakHere since Apple hasn't updated it in awhile.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM