external accessory framework reference

28
External Accessory Framework Reference Data Management: Device Information 2010-05-11

Upload: maheshkmr81

Post on 23-Feb-2015

252 views

Category:

Documents


9 download

TRANSCRIPT

Page 1: External Accessory Framework Reference

External Accessory Framework ReferenceData Management: Device Information

2010-05-11

Page 2: External Accessory Framework Reference

Apple Inc.© 2010 Apple Inc.All rights reserved.

No part of this publication may be reproduced,stored in a retrieval system, or transmitted, inany form or by any means, mechanical,electronic, photocopying, recording, orotherwise, without prior written permission ofApple Inc., with the following exceptions: Anyperson is hereby authorized to storedocumentation on a single computer forpersonal use only and to print copies ofdocumentation for personal use provided thatthe documentation contains Apple’s copyrightnotice.

The Apple logo is a trademark of Apple Inc.

Use of the “keyboard” Apple logo(Option-Shift-K) for commercial purposeswithout the prior written consent of Apple mayconstitute trademark infringement and unfaircompetition in violation of federal and statelaws.

No licenses, express or implied, are grantedwith respect to any of the technology describedin this document. Apple retains all intellectualproperty rights associated with the technologydescribed in this document. This document isintended to assist application developers todevelop applications only for Apple-labeledcomputers.

Every effort has been made to ensure that theinformation in this document is accurate. Appleis not responsible for typographical errors.

Apple Inc.1 Infinite LoopCupertino, CA 95014408-996-1010

Apple, the Apple logo, iPhone, and Objective-Care trademarks of Apple Inc., registered in theUnited States and other countries.

IOS is a trademark or registered trademark ofCisco in the U.S. and other countries and is usedunder license.

Simultaneously published in the United Statesand Canada.

Even though Apple has reviewed this document,APPLE MAKES NO WARRANTY OR REPRESENTATION,EITHER EXPRESS OR IMPLIED, WITH RESPECT TOTHIS DOCUMENT, ITS QUALITY, ACCURACY,MERCHANTABILITY, OR FITNESS FOR A PARTICULARPURPOSE. AS A RESULT, THIS DOCUMENT ISPROVIDED “AS IS,” AND YOU, THE READER, AREASSUMING THE ENTIRE RISK AS TO ITS QUALITYAND ACCURACY.

IN NO EVENT WILL APPLE BE LIABLE FOR DIRECT,INDIRECT, SPECIAL, INCIDENTAL, ORCONSEQUENTIAL DAMAGES RESULTING FROM ANYDEFECT OR INACCURACY IN THIS DOCUMENT, evenif advised of the possibility of such damages.

THE WARRANTY AND REMEDIES SET FORTH ABOVEARE EXCLUSIVE AND IN LIEU OF ALL OTHERS, ORALOR WRITTEN, EXPRESS OR IMPLIED. No Appledealer, agent, or employee is authorized to makeany modification, extension, or addition to thiswarranty.

Some states do not allow the exclusion or limitationof implied warranties or liability for incidental orconsequential damages, so the above limitation orexclusion may not apply to you. This warranty givesyou specific legal rights, and you may also haveother rights which vary from state to state.

Page 3: External Accessory Framework Reference

Contents

Introduction Introduction 5

Part I Classes 7

Chapter 1 EAAccessory Class Reference 9

Overview 9Tasks 9Properties 10Constants 13

Chapter 2 EAAccessoryManager Class Reference 15

Overview 15Tasks 15Properties 16Class Methods 16Instance Methods 17Constants 18Notifications 18

Chapter 3 EASession Class Reference 19

Overview 19Tasks 19Properties 20Instance Methods 21

Part II Protocols 23

Chapter 4 EAAccessoryDelegate Protocol Reference 25

Overview 25Tasks 25Instance Methods 25

Document Revision History 27

32010-05-11 | © 2010 Apple Inc. All Rights Reserved.

Page 4: External Accessory Framework Reference

42010-05-11 | © 2010 Apple Inc. All Rights Reserved.

CONTENTS

Page 5: External Accessory Framework Reference

Framework /System/Library/Frameworks/ExternalAccessory.framework

Header file directories /System/Library/Frameworks/ExternalAccessory.framework/Headers

Companion guide External Accessory Programming Topics

Declared in EAAccessory.hEAAccessoryManager.hEASession.h

The External Accessory framework provides support for communicating with external hardware connectedto an iOS-based device through the 30-pin dock connector or wirelessly using Bluetooth. Applications thatsupport external accessories must be sure to configure their Info.plist file correctly. Specifically, you mustinclude the UISupportedExternalAccessoryProtocols key to declare the specific hardware protocolsyour application supports. For more information about this framework, see External Accessory ProgrammingTopics.

52010-05-11 | © 2010 Apple Inc. All Rights Reserved.

INTRODUCTION

Introduction

Page 6: External Accessory Framework Reference

62010-05-11 | © 2010 Apple Inc. All Rights Reserved.

INTRODUCTION

Introduction

Page 7: External Accessory Framework Reference

72010-05-11 | © 2010 Apple Inc. All Rights Reserved.

PART I

Classes

Page 8: External Accessory Framework Reference

82010-05-11 | © 2010 Apple Inc. All Rights Reserved.

PART I

Classes

Page 9: External Accessory Framework Reference

Inherits from NSObject

Conforms to NSObject (NSObject)

Availability Available in iOS 3.0 and later.

Declared in ExternalAccessory/EAAccessory.h

Related sample code EADemo

Overview

The EAAccessory class provides your application with information about a single connected hardwareaccessory. You can use the information in this class to determine if your application is able to open a sessionto a given accessory. After you have an open session, you can also associate a custom delegate with theaccessory object to be notified to changes in the accessory state. Your delegate must adopt theEAAccessoryDelegate protocol.

You use an accessory object to create an EASession object, which itself provides the communicationschannel to and from the accessory hardware. The accessory object provides information about thecommunications protocols the accessory supports, along with information about current hardware andfirmware revisions.

When deciding whether to connect to an accessory, you should use the accessory’s declared protocols tomake your determination. The protocols associated with an accessory indicate the types of data the accessoryis capable of processing. You may use other properties to help you decide whether or not to connect to anaccessory but the list of protocols should be the key factor you consider.

Accessories can be physically connected to the device through the 30-pin dock connector or wirelessly usingBluetooth.

Tasks

Getting Connection Information

connected (page 10) propertyA Boolean value indicating whether the accessory is currently connected to the iOS-based device.(read-only)

Overview 92010-05-11 | © 2010 Apple Inc. All Rights Reserved.

CHAPTER 1

EAAccessory Class Reference

Page 10: External Accessory Framework Reference

connectionID (page 11) propertyThe accessory’s unique connection ID to the iOS-based device. (read-only)

Getting the Manufacturer-Supplied Attributes

name (page 12) propertyThe display name of the accessory. (read-only)

manufacturer (page 12) propertyThe name of the accessory’s manufacturer. (read-only)

modelNumber (page 12) propertyThe model information for the accessory. (read-only)

serialNumber (page 13) propertyThe serial number of the accessory. (read-only)

firmwareRevision (page 11) propertyThe current firmware version for the accessory. (read-only)

hardwareRevision (page 11) propertyThe hardware version of the accessory. (read-only)

protocolStrings (page 12) propertyThe communication protocols supported by the accessory. (read-only)

Accessing the Delegate

delegate (page 11) propertyThe object that acts as the delegate of the accessory.

Properties

For more about Objective-C properties, see “Properties” in The Objective-C Programming Language.

connectedA Boolean value indicating whether the accessory is currently connected to the iOS-based device. (read-only)

@property(nonatomic, readonly, getter=isConnected) BOOL connected

AvailabilityAvailable in iOS 3.0 and later.

Declared InEAAccessory.h

10 Properties2010-05-11 | © 2010 Apple Inc. All Rights Reserved.

CHAPTER 1

EAAccessory Class Reference

Page 11: External Accessory Framework Reference

connectionIDThe accessory’s unique connection ID to the iOS-based device. (read-only)

@property(nonatomic, readonly) NSUInteger connectionID

DiscussionThe connection ID uniquely identifies this accessory to the device. If multiple accessories of the same typeare connected to the device, you can use this information to distinguish between them.

The connection ID for an accessory persists only for the duration of the current connection. If the accessoryis disconnected and reconnected, a new connection ID is assigned.

AvailabilityAvailable in iOS 3.0 and later.

Declared InEAAccessory.h

delegateThe object that acts as the delegate of the accessory.

@property(nonatomic, assign) id<EAAccessoryDelegate> delegate

DiscussionThe delegate receives notifications about changes to the status of the accessory object. The delegate mustadopt the EAAccessoryDelegate protocol.

AvailabilityAvailable in iOS 3.0 and later.

Declared InEAAccessory.h

firmwareRevisionThe current firmware version for the accessory. (read-only)

@property(nonatomic, readonly) NSString *firmwareRevision

DiscussionThe format of this string is determined by the accessory manufacturer.

AvailabilityAvailable in iOS 3.0 and later.

Declared InEAAccessory.h

hardwareRevisionThe hardware version of the accessory. (read-only)

Properties 112010-05-11 | © 2010 Apple Inc. All Rights Reserved.

CHAPTER 1

EAAccessory Class Reference

Page 12: External Accessory Framework Reference

@property(nonatomic, readonly) NSString *hardwareRevision

DiscussionThe format of this string is determined by the accessory manufacturer.

AvailabilityAvailable in iOS 3.0 and later.

Declared InEAAccessory.h

manufacturerThe name of the accessory’s manufacturer. (read-only)

@property(nonatomic, readonly) NSString *manufacturer

AvailabilityAvailable in iOS 3.0 and later.

Declared InEAAccessory.h

modelNumberThe model information for the accessory. (read-only)

@property(nonatomic, readonly) NSString *modelNumber

AvailabilityAvailable in iOS 3.0 and later.

Declared InEAAccessory.h

nameThe display name of the accessory. (read-only)

@property(nonatomic, readonly) NSString *name

AvailabilityAvailable in iOS 3.0 and later.

Declared InEAAccessory.h

protocolStringsThe communication protocols supported by the accessory. (read-only)

12 Properties2010-05-11 | © 2010 Apple Inc. All Rights Reserved.

CHAPTER 1

EAAccessory Class Reference

Page 13: External Accessory Framework Reference

@property(nonatomic, readonly) NSArray *protocolStrings

DiscussionProtocol names are formatted as reverse-DNS strings. For example, the string “com.apple.myProtocol”might represent a custom protocol defined by Apple. Manufacturers can define custom protocols for theiraccessories or work with other manufacturers and organizations to define standard protocols for differentaccessory types.

The protocol name should be the primary factor in determining whether your application is capable ofcommunicating with a given accessory. You may use other properties to help you decide whether or not toconnect to an accessory but the protocol should still be the key factor you consider. If your applicationsupports multiple protocols for a single accessory, your code should always choose the highest-fidelityprotocol that you support.

AvailabilityAvailable in iOS 3.0 and later.

Related Sample CodeEADemo

Declared InEAAccessory.h

serialNumberThe serial number of the accessory. (read-only)

@property(nonatomic, readonly) NSString *serialNumber

AvailabilityAvailable in iOS 3.0 and later.

Declared InEAAccessory.h

Constants

Null Connection IDIdentifies an unconnected accessory.

enum { EAConnectionIDNone = 0,};

ConstantsEAConnectionIDNone

Indicates an invalid connection.

Available in iOS 3.0 and later.

Declared in EAAccessory.h.

Constants 132010-05-11 | © 2010 Apple Inc. All Rights Reserved.

CHAPTER 1

EAAccessory Class Reference

Page 14: External Accessory Framework Reference

14 Constants2010-05-11 | © 2010 Apple Inc. All Rights Reserved.

CHAPTER 1

EAAccessory Class Reference

Page 15: External Accessory Framework Reference

Inherits from NSObject

Conforms to NSObject (NSObject)

Availability Available in iOS 3.0 and later.

Declared in ExternalAccessory/EAAccessoryManager.h

Related sample code EADemo

Overview

The EAAccessoryManager class coordinates the attached accessories for an iOS-based device. You use thisclass to retrieve a list of accessories to which your application might want to connect. You also use this classto start and stop the sending of accessory-related connect and disconnect notifications.

Tasks

Getting the Shared Accessory Manager

+ sharedAccessoryManager (page 16)Returns the shared EAAccessoryManager object for the iOS-based device.

Starting and Stopping Accessory Notifications

– registerForLocalNotifications (page 17)Begins the delivery of accessory-related notifications to the current application.

– unregisterForLocalNotifications (page 17)Stops the delivery of accessory-related notifications to the current application.

Getting the Available Accessories

connectedAccessories (page 16) propertyThe accessory objects corresponding to the list of currently connected accessories. (read-only)

Overview 152010-05-11 | © 2010 Apple Inc. All Rights Reserved.

CHAPTER 2

EAAccessoryManager Class Reference

Page 16: External Accessory Framework Reference

Properties

For more about Objective-C properties, see “Properties” in The Objective-C Programming Language.

connectedAccessoriesThe accessory objects corresponding to the list of currently connected accessories. (read-only)

@property (nonatomic, readonly) NSArray *connectedAccessories;

DiscussionThis property contains an array of EAAccessory objects. Each object corresponds to an accessory that isconnected and available for your application to use. Because the contents of this property can changedynamically based on the connection and disconnection of accessories, you should not cache the value ofthis property.

AvailabilityAvailable in iOS 3.0 and later.

Related Sample CodeEADemo

Declared InEAAccessoryManager.h

Class Methods

sharedAccessoryManagerReturns the shared EAAccessoryManager object for the iOS-based device.

+ (EAAccessoryManager *)sharedAccessoryManager

Return ValueThe shared accessory manager object.

DiscussionYou should always use this method to obtain the accessory manager object and should not try to createinstances directly.

AvailabilityAvailable in iOS 3.0 and later.

Related Sample CodeEADemo

Declared InEAAccessoryManager.h

16 Properties2010-05-11 | © 2010 Apple Inc. All Rights Reserved.

CHAPTER 2

EAAccessoryManager Class Reference

Page 17: External Accessory Framework Reference

Instance Methods

registerForLocalNotificationsBegins the delivery of accessory-related notifications to the current application.

- (void)registerForLocalNotifications

DiscussionYou must call this method if you want to be notified when accessories become connected or disconnected.The system does not send these notifications automatically, so calling this method lets the system know thatyour application is interested in them. Typically, you would call this method only once early in your application,either before or after configuring your notification observers. When you no longer need to monitor thesenotifications, you should call the matching unregisterForLocalNotifications method.

You can configure your notification observers either before or after calling this method. Because the sharedaccessory manager is the only object that sends accessory-related notifications, specifying that object or nilfor the notification sender has the same outcome.

AvailabilityAvailable in iOS 3.0 and later.

See Also– unregisterForLocalNotifications (page 17)– addObserver:selector:name:object: (NSNotificationCenter)

Related Sample CodeEADemo

Declared InEAAccessoryManager.h

unregisterForLocalNotificationsStops the delivery of accessory-related notifications to the current application.

- (void)unregisterForLocalNotifications

DiscussionTypically, you would call this method either when your application exits or when you no longer want toreceive accessory-related notifications. Calls to this method must be balanced with a preceding call to theregisterForLocalNotifications method.

AvailabilityAvailable in iOS 3.0 and later.

Declared InEAAccessoryManager.h

Instance Methods 172010-05-11 | © 2010 Apple Inc. All Rights Reserved.

CHAPTER 2

EAAccessoryManager Class Reference

Page 18: External Accessory Framework Reference

Constants

Notification User Info KeysKeys associated with the userInfo dictionary of accessory notifications.

NSString *const EAAccessoryKey;

ConstantsEAAccessoryKey

The value assigned to this key is the EAAccessory object whose status changed.

Available in iOS 3.0 and later.

Declared in EAAccessoryManager.h.

Notifications

EAAccessoryDidConnectNotificationPosted when an accessory becomes connected and available for your application to use.

The notification object is the shared accessory manager. The userInfo dictionary contains anEAAccessoryKey, whose value is an EAAccessory object representing the accessory that is now connected.Before delivery of this notification can occur, you must call the registerForLocalNotifications (page17) method to let the system know you are interested in receiving this notification.

AvailabilityAvailable in iOS 3.0 and later.

Declared InEAAccessoryManager.h

EAAccessoryDidDisconnectNotificationPosted when an accessory is disconnected and no longer available for your application to use.

The notification object is the shared accessory manager. The userInfo dictionary contains anEAAccessoryKey, whose value is the EAAccessory object representing the accessory that was disconnected.Before delivery of this notification can occur, you must call the registerForLocalNotifications (page17) method to let the system know you are interested in receiving this notification.

If your accessory manager has a delegate, the delegate can use the accessoryDidDisconnect: (page 25)method to receive this notification instead.

AvailabilityAvailable in iOS 3.0 and later.

Declared InEAAccessoryManager.h

18 Constants2010-05-11 | © 2010 Apple Inc. All Rights Reserved.

CHAPTER 2

EAAccessoryManager Class Reference

Page 19: External Accessory Framework Reference

Inherits from NSObject

Conforms to NSObject (NSObject)

Availability Available in iOS 3.0 and later.

Declared in ExternalAccessory/EASession.h

Related sample code EADemo

Overview

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

After creating a session object, you should immediately retrieve and configure the stream objects providedby 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 availablefor 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 isformatted according to the specified protocol. The EASession class has no knowledge of specific accessoryprotocols and does not attempt to format the data in any way before or after transferring it.

Tasks

Initializing the Session

– initWithAccessory:forProtocol: (page 21)Initializes the session for the specified accessory and protocol.

Getting Session Information

accessory (page 20) propertyThe accessory attached to this session. (read-only)

Overview 192010-05-11 | © 2010 Apple Inc. All Rights Reserved.

CHAPTER 3

EASession Class Reference

Page 20: External Accessory Framework Reference

protocolString (page 21) propertyThe protocol being used for communication with the accessory. (read-only)

Getting the Communication Streams

inputStream (page 20) propertyThe stream to use for receiving data from the accessory. (read-only)

outputStream (page 21) propertyThe stream to use for sending data to the accessory. (read-only)

Properties

For more about Objective-C properties, see “Properties” in The Objective-C Programming Language.

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

@property (nonatomic, readonly) EAAccessory *accessory;

AvailabilityAvailable in iOS 3.0 and later.

Declared InEASession.h

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

@property (nonatomic, readonly) NSInputStream *inputStream;

DiscussionThis stream is provided for you automatically by the session object but you must configure it if you want toreceive any associated stream events. You do this by assigning a delegate to the stream that implementsthe stream:handleEvent: delegate method. This stream handles data transfers asynchronously but deliversstream events on your application’s main thread.

For more information on how to receive data using an input stream, see Stream Programming Guide.

AvailabilityAvailable in iOS 3.0 and later.

Related Sample CodeEADemo

Declared InEASession.h

20 Properties2010-05-11 | © 2010 Apple Inc. All Rights Reserved.

CHAPTER 3

EASession Class Reference

Page 21: External Accessory Framework Reference

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

@property (nonatomic, readonly) NSOutputStream *outputStream;

DiscussionThis stream is provided for you automatically by the session object but you must configure it if you want toreceive any associated stream events. You do this by assigning a delegate to the stream that implementsthe stream:handleEvent: delegate method. This stream handles data transfers asynchronously but alwaysdelivers stream events on your application’s main thread.

For more information on how to send data using an output stream, see Stream Programming Guide.

AvailabilityAvailable in iOS 3.0 and later.

Related Sample CodeEADemo

Declared InEASession.h

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

@property (nonatomic, readonly) NSString *protocolString;

AvailabilityAvailable in iOS 3.0 and later.

Declared InEASession.h

Instance Methods

initWithAccessory:forProtocol:Initializes the session for the specified accessory and protocol.

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

Parametersaccessory

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

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

Instance Methods 212010-05-11 | © 2010 Apple Inc. All Rights Reserved.

CHAPTER 3

EASession Class Reference

Page 22: External Accessory Framework Reference

Return ValueThe initialized session object. This method may return nil if the accessory does not recognize the specifiedprotocol or there was an error communicating with the accessory.

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

AvailabilityAvailable in iOS 3.0 and later.

Related Sample CodeEADemo

Declared InEASession.h

22 Instance Methods2010-05-11 | © 2010 Apple Inc. All Rights Reserved.

CHAPTER 3

EASession Class Reference

Page 23: External Accessory Framework Reference

232010-05-11 | © 2010 Apple Inc. All Rights Reserved.

PART II

Protocols

Page 24: External Accessory Framework Reference

242010-05-11 | © 2010 Apple Inc. All Rights Reserved.

PART II

Protocols

Page 25: External Accessory Framework Reference

Conforms to NSObject

Availability Available in iOS 3.0 and later.

Declared in ExternalAccessory/EAAcessory.h

Related sample code EADemo

Overview

The EAAccessoryDelegate protocol defines a single method for receiving notifications when the associatedEAAccessory object is disconnected. Implementation of this method is optional.

Tasks

Responding to Disconnection Events

– accessoryDidDisconnect: (page 25)Tells the delegate that the specified accessory was disconnected from the device.

Instance Methods

accessoryDidDisconnect:Tells the delegate that the specified accessory was disconnected from the device.

- (void)accessoryDidDisconnect:(EAAccessory *)accessory;

Parametersaccessory

The accessory that was disconnected.

DiscussionThe accessory manager calls this method as a convenience whenever it receives anEAAccessoryDidDisconnectNotification (page 18) notification. You can use this method to removeany references to the specified accessory object and to stop any services currently using the accessory.

Overview 252010-05-11 | © 2010 Apple Inc. All Rights Reserved.

CHAPTER 4

EAAccessoryDelegate Protocol Reference

Page 26: External Accessory Framework Reference

Because this is a convenience method, your delegate does not also need to register as an observer of theEAAccessoryDidDisconnectNotification (page 18) notification. However, if you want your delegateto be notified of newly connected accessories, you should configure it as an observer of theEAAccessoryDidConnectNotification (page 18) notification.

AvailabilityAvailable in iOS 3.0 and later.

Declared InEAAccessory.h

26 Instance Methods2010-05-11 | © 2010 Apple Inc. All Rights Reserved.

CHAPTER 4

EAAccessoryDelegate Protocol Reference

Page 27: External Accessory Framework Reference

This table describes the changes to External Accessory Framework Reference.

NotesDate

Added a link to the External Accessory Programming Topic document.2010-05-11

Added an introduction to the framework collection.2009-07-15

New document describing the classes and methods of the External Accessoryframework.

2009-02-22

272010-05-11 | © 2010 Apple Inc. All Rights Reserved.

REVISION HISTORY

Document Revision History

Page 28: External Accessory Framework Reference

282010-05-11 | © 2010 Apple Inc. All Rights Reserved.

REVISION HISTORY

Document Revision History