Mobile-Menu iFuturz Infoweb Inc. Contact Portfolio



Communicate with External Accessory in iOS.

Communicate with External Accessory in iOS.

Posted On : June 8, 2013

| No Comment

For connect external hardware or accessory with iOS. It’s required to join MFi Program of Apple. This program is basically for the Promote your electronic accessory with MFi logos.

MFi stands for “Made for iPod, iPhone,iPad”

Conclusion is, it’s compulsory to have an MFi registered accessory for Communicate with iPhone.

Another way for communicate external accessory with iOS without join MFi is not possible without using ‘Jail break’ device. You can communicate iPhone with external accessory with the use of Serial communication.

Here, We’ve describe some steps for make communication with external accessory. Which i had study form here.

With the use of serial communication here are steps derived to Communicate with SCR (Smart Card Reader) to iPhone.

Here, We’ve right down some steps like

  • Open Serial Post.
  • Send Data from iPhone to Smart Card Reader.
  • Read Data from Start Card Reader.


Open Serial Port

To open the post given line of code is required

Here, Port name is “/dev/tty.iap”

open("/dev/tty.iap", O_RDWR | O_NOCTTY | O_NONBLOCK)) == -1)

This function returns int value and based on the returned value we can identify success or failure result of port connectivity.

Here is the code to identify the port availability as given below….

serialFD = -1;

if((serialFD = open(“/dev/tty.iap”, O_RDWR | O_NOCTTY | O_NONBLOCK)) == -1)

{NSLog(@"open failed");

return serialFD;


if(ioctl(serialFD, TIOCEXCL) == -1) {



return serialFD;


if(fcntl(serialFD, F_SETFL, 0) == -1) {

NSLog(@"clear O_NONBLOCK");


return serialFD;


// Get original termios

if(tcgetattr(serialFD, &org_termios_s) == -1) {

NSLog(@"get serial original termios");


return serialFD;


Send Data from iPhone to Smart Card Reader


Here, serialFD is the Port Id which you had got after successfully open the post

serialFD = open("/dev/tty.iap", O_RDWR | O_NOCTTY | O_NONBLOCK))

data is HAX value, which you want to send to the external accessory.

And sizeof(uint8_t) indicate the size of &data.


Read Data from Start Card Reader

Read Data from Start Card Reader:

Method of reading Data from external accessory is similar to  write.


Here, This function returns response from external device.  But, Its return any response if at that same time device has send any Request. So, Its recommended to call continuously in background thread for get response from external device.

So this waits in a loop for any signal from external device.