Contents

About External Accessories

Describes how to connect to attached hardware devices.

At a Glance

Communicating with accessories requires information about the accessory itself, which you must obtain from the hardware manufacturer. From there, you use the classes of the External Accessory framework to create the bridge between the hardware and your app.

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.

Declaring the Protocols Your App Supports

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

To declare the protocols your app supports, you must include the UISupportedExternalAccessoryProtocols key in your app’s Info.plist file. This key contains an array of strings that identify the communications protocols that your app supports. Your app 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 app should choose; it uses it only to determine if your app 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 app’s Info.plist file, see Information Property List Key Reference .

Communicating with an Accessory

An app 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 app 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.

Relevant Article: Connecting to an Accessory , Monitoring Accessory-Related Events

See Also

For information about the classes of the External Accessory framework, see External Accessory Framework Reference

Next

Copyright © 2012 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2012-02-24