I would like to write an iPhone/iPad app that can communicate through a USB connection with a Mac or PC program (that I would also write). Does anyone know how I could go about doing this? (I realize that I may have to jailbreak my iPad)
-
1If it's possible at all, you'll definitely have to jailbreak: I know you can't do this with the normal SDK. – Amy Worrall Feb 15 '12 at 17:18
-
An idea would be to try using the serial port (UART or /dev/tty.iap). I'm not sure if you can do it without any additional hardware, but here are some links on the subject : http://devdot.wikispaces.com/Iphone+Serial+Port+Tutorial http://hcgilje.wordpress.com/2010/02/15/iphone-serial-communication/ – adig Feb 16 '12 at 07:12
2 Answers
Socket communication via USB (USBMux) might meet your needs. When an iPad or iPhone plug in to a Mac, there will be a device description /var/run/usbmuxd. You can create a socket and connect it to /var/run/usbmuxd and send/receive packaged data to/or from iOS device. The data should be wrapped.
Here is a brief reference from theiphonewiki http://theiphonewiki.com/wiki/index.php?title=Usbmux. What I can provide is the sample code for connect to usbmuxd.
struct sockaddr_un endpoint;
size_t size;
_usbMuxSocket = socket(PF_LOCAL, SOCK_STREAM, 0);
endpoint.sun_family = AF_LOCAL;
strncpy(endpoint.sun_path, "/var/run/usbmuxd", 17);
size = (offsetof (struct sockaddr_un, sun_path)
+ strlen (endpoint.sun_path) + 1);
connect(_usbMuxSocket, (struct sockaddr *) &endpoint, size);
After that you have to "connect" to the port your App listen on iPad. The "connect" process discussed in the wiki page list above in section Sequence of Events. After the preparing work done, you can use the socket to send and read data.

- 264
- 2
- 8
-
Is there a reason you can't just call 'open' and use that resulting fd? – Dustin Mar 26 '14 at 01:43
Does it have to be a USB connection?
If not, then Robbie Hanson's GCDAsyncSocket is great for connecting all kinds of Apple devices. I used it last year to connect a bunch of iPads to a single app running on a Mac mini.

- 4,502
- 4
- 31
- 56