For your iPhone, you need a MIDI to Lightning connector interface.
There are several products out there. For example the IK Multimedia
http://www.ikmultimedia.com/products/irigmidi/
To connect the M Audio to your iMac, just connect it to the USB port (I guess the M audio has a USB port too). Check in the Audio MIDI Setup utility if your system recognizes the Keyboard, or if you need a Driver. The M Audio website should tell you that.
If you download the free Logic Remote app for iOS (it works with GarageBand despite the "Logic" name), you can actually play your GarageBand instrument via Wi-Fi using the touch interface on iPad (sorry not for iPhones). This is really cool, and you can use some of the unique smart instrument touch interfaces.
I explain in great details how to make all that work in my manuals "GarageBand X - How it Works" and "Logic Remote - How it Works", the only comprehensive books available for those two apps.
Hope that helps
Edgar Rothermich
http://DingDingMusic.com/Manuals/
'I may receive some form of compensation, financial or otherwise, from my recommendation or link.'