iPhone External Accessory Framework

June 30, 2009 § 2 Comments

External Accessory framework is a very new addition to SDK 3.0. It is still a under documented area where there is no code examples offered by Apple.

  • Add ExternalAccessory.framework to Xcode project
  • Add the following lines to any relevant source files .m

#import <ExternalAccessory/ExternalAccessory.h>

Hardware requirement

  • accessory must support at least 1 command protocol
  • decide to use custom protocols or standard protocols supported by other manufacturers
  • to prevent namespace conflicts, protocol names are specified as reverse-DNS strings of the form com.apple.myProtocol
  • manufacturers can define as many protocols
  • use a specific protocol to open a session to accessory
  • create an instance of EASession class
  • EASession class contains NSInputStream and NSOutputStream objects
  • Your app use these stream objects to send raw data packets in receive and send mode
  • must understand expected format of each data packet based on the protocol

Declare the protocols external accessory support in Info.plist file. This declaring support allow system to launch your app when the accessory is connected.

If no app supports the connected accessory, the system may launch the App Store and direct you to the app that support it.

  • Include UISupportedExternalAccessoryProtocols key in Info.plist file
  • This key contains an array of strings that identify the communication protocols your app supported
  • include any no. of protocols in this list in any order
  • system uses this list to determine if your app is capable of communicating with the accessory

Shared EAAccessoryManager object offers the main entry point for applications looking to communicate with accessories. This class contains an array of connected accessory objects such as EAAccessoary object such as name, manufacturer, model information for display purposes.

For a given accessory object, only one session is allowed for a specific protocol. The protocolStrings property of each EAAccessory object contains a dictionary whose keys are ths supported protocols.

After input and output streams are configured, the final step is to process the stream-related data. App doesn’t have to wait for an event before it can write bytes to the stream. It can call the stream’s hasBytesAvailable method to see if the accessory is still able to receive data.

External Accessory framework won’t send notifications when it is connected or disconnected automatically. Your app must call registerForLocalNotifications method in EAAccessoryManager class. Framework sends an EAAccessaryDidConnectNotification notification when an accessory is connected. It sends an EAAccessoryDidDisconnectNotification notification when an accessory is disconnected.

You’ll receive notifications using NSNotificationCenter by default. Delegate objects can handle EAAccessoryDelegate protocol with optional accessoryDidDisconnect: method.

References:

Introduction to Stream Programming Guide for Cocoa

§ 2 Responses to iPhone External Accessory Framework

  • aftab baig says:

    Hi there,
    I am interested in developing for bluetooth devices.
    My client has a bluetooth device that he has registered as ‘made for apple’.

    He is sending me the device.
    But before this, I need to test without the device.

    Is there any possibility ?
    Can I use my mac-mini as a sample device to connect ?

    I will really appreciate any help.
    Thanks,
    Aftab Baig

Leave a reply to aftab baig Cancel reply

What’s this?

You are currently reading iPhone External Accessory Framework at Web Builders.

meta