I'm trying to port a JUCE app from OSX to iOS. The app plays only MIDI data, no audio and does not make use of an AudioDeviceManager. The problem is that while MIDI playback in background works flawlessly in OSX, it does not work at all in iOS. When the app returns to foreground, playback resumes.
I have properly set the UIBackgroundModes property in the iOS project, of course. From what I see in the debugger, the run() method of the playback thread it's simply not called while the app is in background.
Seems inefficient to leave the audio running while the app is suspended, but I guess that if that's what it takes to force iOS to keep running, then that's what you'd need to do!
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.
Well, I'm realizing that I could at least check if my app is actually in playback mode when it is suspended before calling addAudioCallback().
Yes, but switching it on/off adds complexity and possible fail-points to your app. Unless you've profiled it and actually measured a performance issue that justifies the extra complexity, then it's always best to keep things simple.