Telling iOS that my recorder app need not run in background when it is not recording

I’m making a simple recorder app on iOS.
Because I want my app to record while it is background, I enabled “Audio Background Capability” from Projucer.
The problem is, my app always run in background that there is always red notification on the header though I run another app.
It is not critical problem, but is a little annoying for the user.

I want my app not to run in background when it is not recording, and to run in background during recording.

So I have to tell iOS that it should be run in background or not at runtime.
How can I do?

Referring these thread, I implemented like below in MyApp : public juce::JUCEApplication.

void MyApp::resumed()override { }

void MyApp::suspended()override
{
if (!engine.recorder.isNowRecording())
quit();
}

But it is not good because every time user hit the home button and wake it up again, he has to initialize my app.
If you’ve encountered similar problems, or you have any good idea, let me know!
Thanks.

I might solve the problem by myself!

The problem was, at suspended(), I didn’t close audio device when it is not recording.
So my code now looks like that.

void MyApp::resumed()override 
{
    if (!engine.recorder.isNowRecording())
        engine->audioDeviceManager.restartLastAudioDevice();
}

void MyApp::suspended()override
{
    if (!engine.recorder.isNowRecording())
        engine->audioDeviceManager.closeAudioDevice();
}
2 Likes