iOS Reference Library Apple Developer
Search

About External Accessories

The External Accessory framework (ExternalAccessory.framework) provides a conduit for communicating with accessories attached to any iOS-based device. Application developers can use this conduit to integrate accessory-level features into their applications.

Communicating with an external accessory requires you to work closely with the accessory manufacturer to understand the services provided by that accessory. Manufacturers must build explicit support into their accessory hardware for communicating with iOS. As part of this support, an accessory must support at least one command protocol, which is a custom scheme for sending data back and forth between the accessory and an attached application. Apple does not maintain a registry of protocols; it is up to the manufacturer to decide which protocols to support and whether to use custom protocols or standard protocols supported by other manufacturers.

As part of your communication with the accessory manufacturer, you must find out what protocols a given accessory supports. To prevent namespace conflicts, protocol names are specified as reverse-DNS strings of the form com.apple.myProtocol. This allows each manufacturer to define as many protocols as needed to support their line of accessories.

Note: If you are interested in becoming a developer of accessories for iPad, iPhone, or iPod touch, you can find information about how to do so on http://developer.apple.com.

Steps for Communicating with Accessories

An application communicates with an accessory by creating an EASession object for managing the accessory interactions. Session objects work with the underlying system to transfer data packets to and from the accessory. Data transfer in your application occurs through NSInputStream and NSOutputStream objects, which are vended by the session object once the connection is made. To receive data from the accessory, monitor the input stream using a custom delegate object. To send data to the accessory, write data packets to the output stream. The format of the incoming and outgoing data packets is determined by the protocol you use to communicate with the accessory.

For details on how to get a list of connected accessories and start a session with one of them, see “Connecting to an Accessory.”

Including the External Accessory Framework in Your Project

To use the features of the External Accessory framework, you must add ExternalAccessory.framework to your Xcode project and link against it in any relevant targets. To access the classes and headers of the framework, include an #import <ExternalAccessory/ExternalAccessory.h> statement at the top of any relevant source files. For more information on how to add frameworks to your project, see “Files in Projects” in Xcode Project Management Guide. For general information about the classes of the External Accessory framework, see External Accessory Framework Reference.

Declaring the Protocols Your Application Supports

Applications that are able to communicate with an external accessory should declare the protocols they support in their Info.plist file. Declaring support for specific protocols lets the system know that your application can be launched when that accessory is connected. If no application supports the connected accessory, the system may choose to launch the App Store and point out applications that do.

To declare the protocols your application supports, you must include the UISupportedExternalAccessoryProtocols key in your application’s Info.plist file. This key contains an array of strings that identify the communications protocols that your application supports. Your application can include any number of protocols in this list and the protocols can be in any order. The system does not use this list to determine which protocol your application should choose; it uses it only to determine if your application is capable of communicating with the accessory. It is up to your code to choose an appropriate communications protocol when it begins talking to the accessory.

For more information about the keys you put into your application’s Info.plist file, see Information Property List Key Reference.

Organization of This Document

This document includes the following articles:




Last updated: 2010-05-26

Did this document help you? Yes It's good, but... Not helpful...