Microphone background service

Hi,


We are creating an app that needs to run a service in the background even when the app is closed.


In order to do this we will ask the users consent and the user can choose to turn this feature ON or OFF at anytime.


While reading the documentation I have found out that we need to use one of the background modes (in our case the audio access) but I can't find an working example.


Can you help?


We are considering of using the Audio background mode because our background service needs to access the microphone.


Do you have an example of how can we create a background service?


Is it this possible to access the microphone from a background service?


Thank you,

Mircea

Accepted Answer

From the 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

When the UIBackgroundModes key contains the audio value, the system’s media frameworks automatically prevent the corresponding app from being suspended when it moves to the background. As long as it is playing audio or video content or recording audio content, the app continues to run in the background. However, if recording or playback stops, the system suspends the app.

Thanks


The Audio UIBackground mode is what we need to access the microphone.


Regarding the Background Service question:

Is it possible to have a Background Service running even when the App is closed?

(closed not just hidden / minimized)


Something similar to what Siri dose.


Thank you,

Mircea

Is it possible to have a Background Service running even when the App is closed? (closed not just hidden / minimized)

Your app can record audio while it is running in the background. However, if the user quits the app (from the app switcher), your app will be terminated. Apple can run "background services", but third party developers are not allowed to.

Thanks, I guess apple keeps this kind of "background services" to themselves 😟


Another question, when recording with the app in the background I get a Red status bar on the top of the screen.


Can I hide it?


Or can I display a non-closable notification in the notification bar like in Android?


Regards,

Mircea

Another question, when recording with the app in the background I get a Red status bar on the top of the screen. Can I hide it?

You can hide the status bar while your app is in the foreground (on screen), but you cannot hide the status bar when your app is in the background.

Or can I display a non-closable notification in the notification bar like in Android?

I'm not sure what you mean, but I don't think that is possible.


It sounds like you are trying to hide the fact that your app is recording. Because of iOS's security and privacy restrictions, that is not really possible.

Thank you for helping.


We are not trying to hide the fact that the microphone is recording, but if the microphone is recording for a long period (30 minutes or more) I think the user will be bothered by the red status bar.


On Android you can have an Icon in the status bar or a non-closeable notification in the notification panel that shows the user there is an activity running in the background.

In this way the user can continue to use the phone normally, without seeing the red status bar all the time.


Thank you,

Mircea

Like I said, your app can only hide/change the status bar while your app is in the foreground. There is no way for your app to hide/change the status bar while your app is in the background.

Microphone background service
 
 
Q