EASession Class Reference

Inherits from
Conforms to
Availability
Available in iOS 3.0 and later.
Declared in
EASession.h
Related sample code

Overview

The EASession class is used to create a communications channel between your application and a connected hardware accessory. When creating a session, you must specify the protocol you wish to use to communicate with the accessory. After initializing an instance of this class, you use the provided output and input streams to transfer data to and from the accessory using that protocol.

After creating a session object, you should immediately retrieve and configure the stream objects provided by the session. Streams send events to their associated delegate to notify it of changes in the stream status. For example, streams notify the delegate when data is waiting to be read or when more space is available for writing data. For more information about how to use stream objects, see Stream Programming Guide.

When sending and receiving data using the provided streams, it is your responsibility to ensure the data is formatted according to the specified protocol. The EASession class has no knowledge of specific accessory protocols and does not attempt to format the data in any way before or after transferring it.

Tasks

Initializing the Session

Getting Session Information

Getting the Communication Streams

Properties

accessory

The accessory attached to this session. (read-only)

@property (nonatomic, readonly) EAAccessory *accessory;
Availability
  • Available in iOS 3.0 and later.
Declared In
EASession.h

inputStream

The stream to use for receiving data from the accessory. (read-only)

@property (nonatomic, readonly) NSInputStream *inputStream;
Discussion

This stream is provided for you automatically by the session object but you must configure it if you want to receive any associated stream events. You do this by assigning a delegate object to the stream that implements the stream:handleEvent: delegate method. You must then schedule the stream in a run loop so that it can receive data asynchronously from one of your application’s threads.

For information on how to schedule an input stream in a run loop and use it to receive data, see Stream Programming Guide.

Availability
  • Available in iOS 3.0 and later.
Related Sample Code
Declared In
EASession.h

outputStream

The stream to use for sending data to the accessory. (read-only)

@property (nonatomic, readonly) NSOutputStream *outputStream;
Discussion

This stream is provided for you automatically by the session object but you must configure it if you want to receive any associated stream events. You do this by assigning a delegate object to the stream that implements the stream:handleEvent: delegate method. You must then schedule the stream in a run loop so that it can send data asynchronously from one of your application’s threads.

For more information on how to schedule an output stream in a run loop and use it to send data, see Stream Programming Guide.

Availability
  • Available in iOS 3.0 and later.
Related Sample Code
Declared In
EASession.h

protocolString

The protocol being used for communication with the accessory. (read-only)

@property (nonatomic, readonly) NSString *protocolString;
Availability
  • Available in iOS 3.0 and later.
Declared In
EASession.h

Instance Methods

initWithAccessory:forProtocol:

Initializes the session for the specified accessory and protocol.

- (id)initWithAccessory:(EAAccessory *)accessory forProtocol:(NSString *)protocolString
Parameters
accessory

The accessory with which you want to communicate. You can get a list of accessory objects from the EAAccessoryManager object.

protocolString

The protocol to use when communicating with the accessory. This protocol must be one that the accessory understands. All communications with the accessory are expected to use this protocol.

Return Value

The initialized session object. This method may return nil if the accessory does not recognize the specified protocol or there was an error communicating with the accessory.

Discussion

There can be only one session object at a time for a given accessory and protocol combination.

Availability
  • Available in iOS 3.0 and later.
Related Sample Code
Declared In
EASession.h