Circuits for two way data transfer from iPhone to Arduino via headphone jack
Have a look at this project. From what I gather, its an open source project and has some documentation on it (I didn't actually read it)

Android Oscilloscope

They used the microphone input (similiar to what you are doing) and then displaying it through an app (also open source). If you go over their stuff, you should be able to figure out, how they are reading back values. You can then write your own app so that, if you see a specific voltage, voltage range, or a specific frequency ( fft or other algorithm), you can do something with your app, or send data out through the headphones.

To send data to your iphone/android device, you would need to generate an voltage or voltage signal. That can probably be done using PWM and a low pass filter. I don't know what safe voltages are for cell phone microphone inputs, so find that out too.

Hopefully, this is a start to aid you in your research. 

I haven't done any of the things I said, so do your research!