Read Me about EADemo
EADemo shows how to communicate from an iOS 3.x application, with an external accessory using the External Accessory (EA) Framework API. The sample can be used with a Made For iPod (MFI) accessory, which supports the iPod Accessory Protocol (see http://developer.apple.com/iphone/program/sdk/accessories.html) designed for use with the ExternalAccessory.framework. The sample is provided to demonstrate the common functions of an EA Framework application. The goal of this sample is to demonstrate the following functions
- detect the connections and disconnections of accessories that support EA protocols.
- provide a demonstration for communicating with the accessory.
EADemo requires iOS 4 or later to run on an iPhone or iPod Touch.
EADemo requires iOS 3.2 to run on an iPad.
The sample contains the following items:
o ReadMe.txt -- This file.
o EADemo_Prefix.pch -- Prefix header for all source files in the EADemo project.
o EADemo.xcodeproj -- An Xcode project for the sample.
o EADemo-Info.plist -- The application Info.plist file.
o EADSessionController.[hm] -- Provides an interface for communication with an EASession. It is also the delegate for the EASession input and output stream objects.
o EADSessionTransferViewController.[hm] -- A view controller to allow transferring data to and from an accessory form the UI.
o EADemoAppDelegate.[hm] -- A delegate object for the User Interface.
o RootViewController.[hm] -- A table view controller for watching the device come and go.
Using the Sample
The sample can be used with any Made For iPod (MFI) accessory designed for use with the External Accessory Framework. The application will display all attached External Accessories in the "Accessories" table view, provide information registered by the MFI accessory, and provides methods to send and receive data to the accessory. Information about MFI accessories is available to licensees of the MFI program. You can learn more about the MFI program at the Apple Developer Connection "Made For iPod Program" web page <http://developer.apple.com/ipod/index.html>.
When the MFI accessory is attached, iOS reads the MFI accessory provided information that includes the supported protocol strings. The system searches for a matching protocol string in the UISupportedExternalAccessoryProtocols array of the Info.plist of all the installed applications. If no matching protocol string is found, iOS raises the "Application Not Installed" alert. You can modify the UISupportedExternalAccessoryProtocols property in the EADemo-Info.plist to include the protocol string registered by your accessory, to keep the system from presenting the "Application Not Installed" alert on accessory attachment.
At the "Accessories" table view, the name of all attached MFI accessories are displayed. Click on the accessory name to see a list of supported protocols. Select a protocol, and the application will use the protocol to open a session for communication with the accessory.
The Protocol table view provides options for three different ways to send data to the accessory. There is also a counter to display the number of bytes received from the accessory. The three buttons and the methods that are called are
"Send String" - sendString - sends the string entered in the UITextField it's associated with in the view to the accessory.
"Send Hex Data" - sendHex - sends the string entered in the UITextField it's associated with in the view interpreted as a hex byte sequence to the accessory.
"Send 10K" - send10K - sends 10K bytes of incrementing 8-bit values (0 to 255) to the accessory.
If the accessory is detached, the application will detect this action and reset itself to the main Accessories table view. When no accessory is attached, the main screen will display the message "No Accessories Connected".
Building the Sample
The sample requires Xcode 3.2.3 on Mac OS X 10.6 with iOS 4 SDK.
The sample program will run in the Simulator, but there is is no support communicate with real accessories through the simulator.
Credits and Version History
If you find any problems with this sample, please file a bug against it.
Apple Developer Technical Support
10 July 2010
© 2010 Apple Inc. All Rights Reserved. (Last updated: 2010-07-26)