The RTP-MIDI protocol lets device exchange MIDI data over the network, such as Wi-Fi or LAN.
To minimize the latency, I recommend connecting devices using a LAN cable if possible. Using an ad-hoc Wi-Fi network can also give lower latency than having 2 devices communicate via a Wi-Fi router.
See “Share MIDI information over a network in Audio MIDI Setup on Mac” on Apple Support for more information.
Windows users can use the rtpMIDI driver. It is free for private, non-commercial use.
Use the MIDI Network app to connect your iOS device to other RTP-MIDI capable devices.