iOS Developer Library

Developer

EASession Class Reference

Options
Deployment Target:

On This Page
Language:

EASession

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. More...

Inheritance


Conforms To


Import Statement


import ExternalAccessory @import ExternalAccessory;

Availability


Available in iOS 3.0 and later.
  • Initializes the session for the specified accessory and protocol.

    Declaration

    Swift

    init!(accessory accessory: EAAccessory!, forProtocol protocolString: String!)

    Objective-C

    - (instancetype)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.

    Import Statement

    import ExternalAccessory

    Availability

    Available in iOS 3.0 and later.

  • accessory accessory Property

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

    Declaration

    Swift

    var accessory: EAAccessory! { get }

    Objective-C

    @property(nonatomic, readonly) EAAccessory *accessory

    Import Statement

    import ExternalAccessory

    Availability

    Available in iOS 3.0 and later.

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

    Declaration

    Swift

    var protocolString: String! { get }

    Objective-C

    @property(nonatomic, readonly) NSString *protocolString

    Import Statement

    import ExternalAccessory

    Availability

    Available in iOS 3.0 and later.

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

    Declaration

    Swift

    var inputStream: NSInputStream! { get }

    Objective-C

    @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.

    Import Statement

    import ExternalAccessory

    Availability

    Available in iOS 3.0 and later.

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

    Declaration

    Swift

    var outputStream: NSOutputStream! { get }

    Objective-C

    @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.

    Import Statement

    import ExternalAccessory

    Availability

    Available in iOS 3.0 and later.