Receiving midi from network "Session 1" on iOS

I have written an app that reads midi on iOS. By default (without any device connected), the device name is “Network Session 1”. I use an other application like Geoshred/Midikeys to send midi to my app. However, I don’t receive midi on this port at all. If a named port is used in the sending application, I am able to receive midi messages correctly. Do I have to do something extra to receive midi messages that are broadcast by other applications. I see that applications like Midi Wrench can detect midi signals output to Network Session 1. I debugged juce code and saw that the call back routine right at the beginning of the chain (newMidiInputProc) was not getting called for “Networking Session”

Thanks for your help

To test this, I commented out the TARGET_OS_SIMULATOR checks in juce_audio_devices.cpp and This means that all apps (even those not built for the simulator) will start and enable a network MIDI session. (This is not a good idea in your own app - you should write your own function to set up a session with appropriate settings.)

Then, I built the DemoRunner for a physical iPhone, the iPhone simulator, and for my Mac. I ran the “Audio → Midi Demo”, selecting the network session as an input and output on all devices. After connecting to iPhone and Simulator from the mac, clicking the MIDI keyboard on the mac will cause messages to appear in the list of “Received MIDI Messages” on the iPhone and Simulator. A breakpoint in newMidiInputProc is hit when messages are sent over the network from another device.

If I then press “Home” on the iPhone, or switch apps, then the app seems to no longer receive midi messages from the network. A breakpoint in newMidiInputProc is no longer hit when the app is not in the foreground.

I then tried enabling the “Audio, AirPlay, and Picture in Picture” background mode in the “Signing & Capabilities” tab of the Xcode project. Now, the iPhone is able to keep receiving messages, even when it is not in the foreground.

To sum up, it looks like this is possible in JUCE, but you will need to:

  • enable the audio background mode in the Xcode project (there’s an “Audio Background Capability” option in the Projucer, and a BACKGROUND_AUDIO_ENABLED option in CMake to do this automatically)
  • keep an audio output running, in addition to the midi input (even if the audio output is just producing silence). This will prevent the app from being suspended when it is no longer in the foreground.

There’s a little more information in this thread: Background MIDI playback in iOS - #5 by hladik

Thanks for your response. I had enabled the background mode. I will also now enable networking session that is currently under the macro TARGET_OS_SIMULATOR and let you know.