Audio stops after app goes to background iPhone 7+8

A bug has recently been reported on a JUCE-based iOS app. The only devices reported are iPhone 7 and 8.

When the app is moved to the background (suspended), the audio device is closed. Upon resuming, the audio device is restarted. On the reported devices, and from my testing with an iPhone 7, the audio does not work after resuming.

I noticed the following error message on the AudioDeviceManager::initialise call when resuming:

 AVAudioSession.mm:1049:-[AVAudioSession setActive:withOptions:error:]: Deactivating an audio session that has running I/O. All I/O should be stopped or paused prior to deactivating the audio session.
JUCE Assertion failure in juce_ios_Audio.cpp:207

I’d assume that closeAudioDevice() would stop the audio and close the I/O thread. All audio callbacks are removed prior to the call, and added after initialise.

I also noticed that sometimes if the app is in the foreground while the device goes to sleep, the audio will come back once the device has “woken up”